You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With at_depth in purrr pre-0.2.3, it is possible to run the following code, but modify_depth breaks the code as it tries to modify .x. I understand modify_depth may not be intended to be backward-compatible, but is there an alternative function with at_depth like behavior in 0.2.3?
Thanks for the powerful package and the improvement in the new version!
# See https://stackoverflow.com/a/43861746/688693 for more details
devtools::install_version("purrr", version = "0.2.2.2", repos = "http://cran.us.r-project.org")
library(gapminder)
library(dplyr)
library(tidyr)
library(purrr)
library(broom)
fmlas <- tibble::tribble(
~continent, ~formula,
"Asia", ~lm(lifeExp ~ year, data = .),
"Europe", ~lm(lifeExp ~ year + pop, data = .),
"Africa", ~lm(lifeExp ~ year + gdpPercap, data = .),
"Americas", ~lm(lifeExp ~ year - 1, data = .),
"Oceania", ~lm(lifeExp ~ year + pop + gdpPercap, data = .)
)
by_continent <- gapminder %>%
nest(-continent) %>%
left_join(fmlas) %>%
mutate(model=map2(data, formula, ~at_depth(.x, 0, .y)))
by_continent %>%
mutate(glance=map(model, glance)) %>%
unnest(glance, .drop=T)
detach(package:purrr, unload=TRUE)
devtools::install_version("purrr", version = "0.2.3", repos = "http://cran.us.r-project.org")
library(purrr)
by_continent <- gapminder %>%
nest(-continent) %>%
left_join(fmlas) %>%
mutate(model=map2(data, formula, ~modify_depth(.x, 0, .y)))
# Error in mutate_impl(.data, dots) :
# Evaluation error: replacement element 7 has 5 rows, need 396.
## OR
by_continent <- gapminder %>%
nest(-continent) %>%
left_join(fmlas) %>%
mutate(model=map2(data, formula, ~modify(.x, .y)))
#Error in mutate_impl(.data, dots) :
# Evaluation error: object 'lifeExp' not found.
The text was updated successfully, but these errors were encountered:
With
at_depth
inpurrr
pre-0.2.3, it is possible to run the following code, butmodify_depth
breaks the code as it tries to modify.x
. I understandmodify_depth
may not be intended to be backward-compatible, but is there an alternative function withat_depth
like behavior in 0.2.3?Thanks for the powerful package and the improvement in the new version!
The text was updated successfully, but these errors were encountered: