I'm getting the message Error: invalid model formula in ExtractVars
while trying to fit linear models using tidyr version 0.4.0. I have run this exact code without error in a previous session, but have changed some library info, so I'm wondering if that is perhaps the issue.
Here's the code I'm trying to run:
library(gapminder)
library(dplyr)
library(tidyr)
library(ggplot2)
library(purrr)
library(broom)
# create one dataframe for each country
by_country <- gapminder %>%
group_by(continent, country) %>%
nest()
# fit a linear model to each country with purrr, save as new var 'model'
by_country <- by_country %>%
mutate(model = purrr::map(data, ~ lm(lifeExp ~ year, data = .)))
Here's my session info:
R version 3.2.2 (2015-08-14) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1
locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages: [1] stats graphics grDevices utils datasets methods base
other attached packages: [1] dplyr_0.4.3 broom_0.4.0 purrr_0.2.0 tidyr_0.4.0 gapminder_0.2.0 lubridate_1.3.3
[7] stringr_1.0.0 ggplot2_1.0.1 plyr_1.8.3 reshape_0.8.5 ProjectTemplate_0.6loaded via a namespace (and not attached): [1] Rcpp_0.12.3 magrittr_1.5 MASS_7.3-43 mnormt_1.5-3 munsell_0.4.2 lattice_0.20-33 colorspace_1.2-6 R6_2.1.2
[9] tools_3.2.2 parallel_3.2.2 grid_3.2.2 nlme_3.1-121 gtable_0.1.2 psych_1.5.8 DBI_0.3.1 lazyeval_0.1.10 [17] digest_0.6.8 assertthat_0.1 reshape2_1.4.1 memoise_1.0.0 labeling_0.3 stringi_1.0-1 scales_0.3.0 proto_0.3-10
I'm using ProjectTemplate, which automatically loads these libraries before running the above code (I think): reshape
, plyr
, ggplot2
, stringr
, lubridate
, gapminder
, tidyr
, purrr
, broom
, dplyr
. I realize there is some duplication, but don't think it would cause the code not to run? Any insight is super appreciated!