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

pkg::fun doesn't work in dplyr::funs #2089

Closed
ghost opened this issue Aug 25, 2016 · 2 comments · Fixed by #2569
Closed

pkg::fun doesn't work in dplyr::funs #2089

ghost opened this issue Aug 25, 2016 · 2 comments · Fixed by #2569
Assignees
Labels
bug an unexpected problem or unintended behavior

Comments

@ghost
Copy link

ghost commented Aug 25, 2016

This works:

slci_msa_wide <- slci_msa %>%
  dplyr::select(principal_city_property, placement_care_type, value_msa) %>%
  tidyr::spread(placement_care_type, value_msa) %>%
  dplyr::left_join(
    dplyr::distinct(slci_msa, principal_city_property, pop_rank)
  ) %>%
  dplyr::arrange(-A) %>%
  dplyr::mutate(cost_rank = row_number()) %>%
  dplyr::arrange(A) %>%
  dplyr::mutate(affordability_rank = row_number()) %>%
  dplyr::select(principal_city_property, dplyr::contains("rank"), A, R, Z) %>%
  dplyr::mutate_at(dplyr::vars(A, R, Z), dplyr::funs(round)) %>%
  dplyr::mutate_at(dplyr::vars(A, R, Z), dplyr::funs(dollar))

But this doesn't, and the only think I changed is the last line, resulting in an error: "Error: cannot coerce type 'closure' to vector of type 'character'"

slci_msa_wide <- slci_msa %>%
  dplyr::select(principal_city_property, placement_care_type, value_msa) %>%
  tidyr::spread(placement_care_type, value_msa) %>%
  dplyr::left_join(
    dplyr::distinct(slci_msa, principal_city_property, pop_rank)
  ) %>%
  dplyr::arrange(-A) %>%
  dplyr::mutate(cost_rank = row_number()) %>%
  dplyr::arrange(A) %>%
  dplyr::mutate(affordability_rank = row_number()) %>%
  dplyr::select(principal_city_property, dplyr::contains("rank"), A, R, Z) %>%
  dplyr::mutate_at(dplyr::vars(A, R, Z), dplyr::funs(round)) %>%
  dplyr::mutate_at(dplyr::vars(A, R, Z), dplyr::funs(scales::dollar))

I think I understand why this is happening, but it causes me to violate best practice in calling functions, which is to call out the package, too.

@VincentGuyader
Copy link

I also find this "bug" :


iris %>%
  mutate(NEW=plyr::revalue(Species,c("virginica"="a","setosa"="b"))) %>%
  summary() # OK

iris %>%
  mutate_each(funs(plyr::revalue(.,c("virginica"="a","setosa"="b"))),Species) %>%
  summary() # DONT WORK.. but it should be, isnt'it ?

plop <-plyr::revalue # ninja tips
iris %>%
  mutate_each(funs(plop(.,c("virginica"="a","setosa"="b"))),Species) %>%
  summary() # OK

@krlmlr
Copy link
Member

krlmlr commented Nov 7, 2016

#2140 looks like a more recent duplicate, and #2057 like an older one.

@hadley hadley added bug an unexpected problem or unintended behavior data frame labels Feb 2, 2017
@hadley hadley added nse and removed data frame labels Feb 20, 2017
lionel- added a commit to lionel-/dplyr that referenced this issue Mar 22, 2017
lionel- added a commit to lionel-/dplyr that referenced this issue Mar 24, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jun 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants