Public-Health-Scotland / phsmethods

An R package to standardise methods used in Public Health Scotland (https://public-health-scotland.github.io/phsmethods/)
https://public-health-scotland.github.io/phsmethods/
54 stars 13 forks source link

Could `format_postcode` have a `quiet` parameter to suppress warning messages #90

Closed Moohan closed 9 months ago

Moohan commented 1 year ago

When you give format_postcode some non-NA invalid postcodes it prints out a warning. This is usually fine, but I have a use case where we are using it to format postcodes but also remove any invalid ones (we have a lot of crap in the data). I think this isn't a particularly unusual use case? It's annoying that I get a big warning message, and the only workaround for me is to wrap it in suppressWarnings()

Current:

dplyr::mutate(
     dplyr::across(contains("postcode"), phsmethods::format_postcode)
 )
Warning message:
Problem while computing `..1 = dplyr::across(contains("postcode"),
phsmethods::format_postcode)`.
ℹ 19 non-NA input values do not adhere to the standard UK postcode format
  (with or without spaces) and will be coded as NA. The standard format is: 
 • 1 or 2 letters, followed by 
 • 1 number, followed by
 • 1 optional letter or number, followed by 
 • 1 number, followed by • 2 letters

Workaround:

dplyr::mutate(
     dplyr::across(contains("postcode"), ~suppressWarnings(phsmethods::format_postcode(.x))
 )

Ideal solution:

dplyr::mutate(
     dplyr::across(contains("postcode"), phsmethods::format_postcode, quiet = TRUE)
 )