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

Deprecated functions from dplyr: funs #599

Closed
dfalster opened this issue Aug 9, 2022 · 0 comments
Closed

Deprecated functions from dplyr: funs #599

dfalster opened this issue Aug 9, 2022 · 0 comments

Comments

@dfalster
Copy link
Member

dfalster commented Aug 9, 2022

dplyr no longer uses mutate_at(vars(...), funs(...)) syntax, which is used in the custom_R_code from Dwyer_2017. Results in a warning, which will shortly elevate to failure as

options(warn=2)
remake::make("Dwyer_2017")
[ BUILD ] Dwyer_2017                     |  Dwyer_2017 <- dataset_process("data/Dwyer_2017/data.csv", Dwyer_2017_con...
Error: (converted from warning) `funs()` was deprecated in dplyr 0.8.0.
Please use a list of either functions or lambdas: 

  # Simple named list: 
  list(mean = mean, median = median)

  # Auto named with `tibble::lst()`: 
  tibble::lst(mean, median)

  # Using lambdas
  list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
This warning is displayed once every 8 hours.
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated

Looking ay the custom_R_code for Dwyer_2017 we have

data <- read_csv("data/Dwyer_2017/data.csv")

data %>% 
     group_by(species, remnant) %>% 
     mutate(
         count_plants = sum(count), 
         seed_mass = round(seed_mass,6), 
         max_height = round(max_height,6), 
         specific_leaf_area = round(specific_leaf_area,6)
     ) %>% 
     mutate_at(vars(count_plants,max_height, specific_leaf_area),
               funs(replace(.,duplicated(.),NA))) %>% 
     ungroup() %>% 
     group_by(species) %>% 
     mutate_at(vars(seed_mass),funs(replace(.,duplicated(.),NA))) %>% 
     ungroup()

Note the custom function has now been formalised as a function replace_duplicates_with_NA

So the line

     mutate_at(vars(count_plants,max_height, specific_leaf_area),
               funs(replace(.,duplicated(.),NA))) %>% 

can be modified as

mutate(
    across(c(count_plants, max_height, specific_leaf_area), replace_duplicates_with_NA))
dfalster added a commit that referenced this issue Aug 9, 2022
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

1 participant