Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove blob/units convenience functions #10

Open
sebdalgarno opened this issue Feb 27, 2018 · 3 comments
Open

remove blob/units convenience functions #10

sebdalgarno opened this issue Feb 27, 2018 · 3 comments

Comments

@sebdalgarno
Copy link
Member

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
Copy link
Member Author

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
Copy link
Member Author

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
Copy link
Member

joethorley commented Mar 2, 2018

yes this last solution seems very elegant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants