poissonconsulting / poisdata

An R package of Poisson Consulting's data handling functions
https://poissonconsulting.github.io/poisdata/
Other
0 stars 2 forks source link

remove blob/units convenience functions #10

Open sebdalgarno opened 6 years ago

sebdalgarno commented 6 years ago

three common operations at the top of clean/tidy-data scripts are/could be:

  1. deactivating sfcs (slows down functions so best to have default off for all data.frames
  2. removing units (have to convert to numeric/integer before some functions can access or compare)
  3. removing blobs (the odd time I'll get caught using View() on a data/frame with a blob column, which causes Rstudio to freeze).

ideally these would be done by using ps_env_map_df() at the moment, ps_env_map_df(ps_deactivate_sfc()) is possible I think ps_env_map_df(ps_deactivate_units()) and ps_env_map_df(ps_remove_blobs()) would be useful enough to have their own functions.

sebdalgarno commented 6 years ago

remove units with ability to guess integer/numeric:

is.units <- function(x) inherits(x, 'units')
to_numeric <- function(x) {
  if(all(x == floor(x), na.rm = T)) 
    return(as.integer(x))
as.numeric(x)
}
ps_strip_units <- function(x) modify_if(x, is.units, to_numeric)

let me know if you have any suggestions

sebdalgarno commented 6 years ago

there is a simpler method that works - as.vector:

is.units <- function(x) inherits(x, 'units')
ps_strip_units <- function(x) modify_if(x, is.units, as.vector)
joethorley commented 6 years ago

yes this last solution seems very elegant