Hello,
using rename, for example:
df = data.frame(old = 1:3) %>% rename(new = old) throws an error:
Error: new = old must be a symbol or a string, not formula
The above is in R 3.4.3
In R 3.4.2 it works as expected.
I do not know if this is a known issue, but just came to my attention and wanted to let you know.
Dimitris
See https://github.com/tidyverse/dplyr/issues/3239#issuecomment-348804671
That was in 3.4.2, though, so I'll have to check and see. What version of dplyr are you running? Could you make a reprex?
A lot of other people seeing this issue had a development version of rlang installed. You might want to check that with packageVersion("rlang") (current CRAN is 0.1.4, something ending in extra nines is common for development versions).
Thanks, John. @dpolychr, if you could make a reprex, or post your sessionInfo, that'd be great. Thanks.
I've had this problem recently too. John is correct.
This is likely a non-issue though, just something to be aware of. Just tell people to be consistent in their use of dev / CRAN versions of dplyr & rlang. Looks like it gets fixed by using tidyselect::vars_rename() in rename() rather than rename_vars().
Works - CRAN dplyr & rlang
# install.packages("dplyr")
# install.packages("rlang")
library(dplyr)
library(rlang)
iris %>%
as_tibble() %>%
rename(my_species = Species)
#> # A tibble: 150 x 5
#> Sepal.Length Sepal.Width Petal.Length Petal.Width my_species
#> <dbl> <dbl> <dbl> <dbl> <fctr>
#> 1 5.10 3.50 1.40 0.200 setosa
#> 2 4.90 3.00 1.40 0.200 setosa
#> 3 4.70 3.20 1.30 0.200 setosa
#> 4 4.60 3.10 1.50 0.200 setosa
#> 5 5.00 3.60 1.40 0.200 setosa
#> 6 5.40 3.90 1.70 0.400 setosa
#> 7 4.60 3.40 1.40 0.300 setosa
#> 8 5.00 3.40 1.50 0.200 setosa
#> 9 4.40 2.90 1.40 0.200 setosa
#> 10 4.90 3.10 1.50 0.100 setosa
#> # ... with 140 more rows
devtools::session_info()
#> Session info -------------------------------------------------------------
#> setting value
#> version R version 3.4.2 Patched (2017-10-05 r73475)
#> system x86_64, darwin15.6.0
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> tz <NA>
#> date 2017-12-17
#> Packages -----------------------------------------------------------------
#> package * version date
#> assertthat 0.2.0 2017-04-11
#> backports 1.1.0 2017-05-22
#> base * 3.4.2 2017-10-06
#> bindr 0.1 2016-11-13
#> bindrcpp 0.2 2017-06-17
#> compiler 3.4.2 2017-10-06
#> datasets * 3.4.2 2017-10-06
#> devtools 1.13.3 2017-08-02
#> digest 0.6.12 2017-01-27
#> dplyr * 0.7.4 2017-09-28
#> evaluate 0.10.1 2017-06-24
#> glue 1.2.0 2017-10-29
#> graphics * 3.4.2 2017-10-06
#> grDevices * 3.4.2 2017-10-06
#> htmltools 0.3.6 2017-04-28
#> knitr 1.17 2017-08-10
#> magrittr 1.5 2014-11-22
#> memoise 1.1.0 2017-10-26
#> methods * 3.4.2 2017-10-06
#> pillar 0.0.0.9000 2017-11-29
#> pkgconfig 2.0.1 2017-03-21
#> R6 2.2.2 2017-06-17
#> Rcpp 0.12.14 2017-11-23
#> rlang * 0.1.4 2017-11-05
#> rmarkdown 1.6.0.9004 2017-09-23
#> rprojroot 1.2 2017-01-16
#> stats * 3.4.2 2017-10-06
#> stringi 1.1.5 2017-04-07
#> stringr 1.2.0 2017-02-18
#> tibble 1.3.4.9003 2017-11-29
#> tools 3.4.2 2017-10-06
#> utils * 3.4.2 2017-10-06
#> withr 2.1.0.9000 2017-11-29
#> yaml 2.1.14 2016-11-12
#> source
#> CRAN (R 3.4.0)
#> CRAN (R 3.4.0)
#> local
#> CRAN (R 3.4.0)
#> CRAN (R 3.4.0)
#> local
#> local
#> CRAN (R 3.4.1)
#> CRAN (R 3.4.0)
#> CRAN (R 3.4.2)
#> CRAN (R 3.4.0)
#> cran (@1.2.0)
#> local
#> local
#> CRAN (R 3.4.0)
#> cran (@1.17)
#> CRAN (R 3.4.0)
#> Github (hadley/memoise@d63ae9c)
#> local
#> Github (r-lib/pillar@5a082e1)
#> CRAN (R 3.4.0)
#> CRAN (R 3.4.0)
#> CRAN (R 3.4.3)
#> CRAN (R 3.4.2)
#> Github (DavisVaughan/rmarkdown@f85ba35)
#> CRAN (R 3.4.0)
#> local
#> CRAN (R 3.4.0)
#> CRAN (R 3.4.0)
#> Github (tidyverse/tibble@60281b3)
#> local
#> local
#> Github (jimhester/withr@fe81c00)
#> CRAN (R 3.4.0)
Fails - CRAN dplyr, but dev rlang
# devtools::install_github("tidyverse/rlang")
# restart R
library(dplyr)
library(rlang)
iris %>%
as_tibble() %>%
rename(my_species = Species)
#> Error: `my_species` = Species must be a symbol or a string, not formula
devtools::session_info()
#> Session info -------------------------------------------------------------
#> setting value
#> version R version 3.4.2 Patched (2017-10-05 r73475)
#> system x86_64, darwin15.6.0
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> tz <NA>
#> date 2017-12-17
#> Packages -----------------------------------------------------------------
#> package * version date
#> assertthat 0.2.0 2017-04-11
#> backports 1.1.0 2017-05-22
#> base * 3.4.2 2017-10-06
#> bindr 0.1 2016-11-13
#> bindrcpp 0.2 2017-06-17
#> compiler 3.4.2 2017-10-06
#> datasets * 3.4.2 2017-10-06
#> devtools 1.13.3 2017-08-02
#> digest 0.6.12 2017-01-27
#> dplyr * 0.7.4 2017-09-28
#> evaluate 0.10.1 2017-06-24
#> glue 1.2.0 2017-10-29
#> graphics * 3.4.2 2017-10-06
#> grDevices * 3.4.2 2017-10-06
#> htmltools 0.3.6 2017-04-28
#> knitr 1.17 2017-08-10
#> magrittr 1.5 2014-11-22
#> memoise 1.1.0 2017-10-26
#> methods * 3.4.2 2017-10-06
#> pillar 0.0.0.9000 2017-11-29
#> pkgconfig 2.0.1 2017-03-21
#> R6 2.2.2 2017-06-17
#> Rcpp 0.12.14 2017-11-23
#> rlang * 0.1.4.9000 2017-12-17
#> rmarkdown 1.6.0.9004 2017-09-23
#> rprojroot 1.2 2017-01-16
#> stats * 3.4.2 2017-10-06
#> stringi 1.1.5 2017-04-07
#> stringr 1.2.0 2017-02-18
#> tibble 1.3.4.9003 2017-11-29
#> tools 3.4.2 2017-10-06
#> utils * 3.4.2 2017-10-06
#> withr 2.1.0.9000 2017-11-29
#> yaml 2.1.14 2016-11-12
#> source
#> CRAN (R 3.4.0)
#> CRAN (R 3.4.0)
#> local
#> CRAN (R 3.4.0)
#> CRAN (R 3.4.0)
#> local
#> local
#> CRAN (R 3.4.1)
#> CRAN (R 3.4.0)
#> CRAN (R 3.4.2)
#> CRAN (R 3.4.0)
#> cran (@1.2.0)
#> local
#> local
#> CRAN (R 3.4.0)
#> cran (@1.17)
#> CRAN (R 3.4.0)
#> Github (hadley/memoise@d63ae9c)
#> local
#> Github (r-lib/pillar@5a082e1)
#> CRAN (R 3.4.0)
#> CRAN (R 3.4.0)
#> CRAN (R 3.4.3)
#> Github (tidyverse/rlang@cc7587c)
#> Github (DavisVaughan/rmarkdown@f85ba35)
#> CRAN (R 3.4.0)
#> local
#> CRAN (R 3.4.0)
#> CRAN (R 3.4.0)
#> Github (tidyverse/tibble@60281b3)
#> local
#> local
#> Github (jimhester/withr@fe81c00)
#> CRAN (R 3.4.0)
Works - dev dplyr & rlang
# devtools::install_github("tidyverse/rlang")
# devtools::install_github("tidyverse/dplyr")
# restart R
library(dplyr)
library(rlang)
iris %>%
as_tibble() %>%
rename(my_species = Species)
#> # A tibble: 150 x 5
#> Sepal.Length Sepal.Width Petal.Length Petal.Width my_species
#> <dbl> <dbl> <dbl> <dbl> <fctr>
#> 1 5.10 3.50 1.40 0.200 setosa
#> 2 4.90 3.00 1.40 0.200 setosa
#> 3 4.70 3.20 1.30 0.200 setosa
#> 4 4.60 3.10 1.50 0.200 setosa
#> 5 5.00 3.60 1.40 0.200 setosa
#> 6 5.40 3.90 1.70 0.400 setosa
#> 7 4.60 3.40 1.40 0.300 setosa
#> 8 5.00 3.40 1.50 0.200 setosa
#> 9 4.40 2.90 1.40 0.200 setosa
#> 10 4.90 3.10 1.50 0.100 setosa
#> # ... with 140 more rows
devtools::session_info()
#> Session info -------------------------------------------------------------
#> setting value
#> version R version 3.4.2 Patched (2017-10-05 r73475)
#> system x86_64, darwin15.6.0
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> tz <NA>
#> date 2017-12-17
#> Packages -----------------------------------------------------------------
#> package * version date
#> assertthat 0.2.0 2017-04-11
#> backports 1.1.0 2017-05-22
#> base * 3.4.2 2017-10-06
#> bindr 0.1 2016-11-13
#> bindrcpp 0.2 2017-06-17
#> compiler 3.4.2 2017-10-06
#> datasets * 3.4.2 2017-10-06
#> devtools 1.13.3 2017-08-02
#> digest 0.6.12 2017-01-27
#> dplyr * 0.7.4.9000 2017-12-17
#> evaluate 0.10.1 2017-06-24
#> glue 1.2.0 2017-10-29
#> graphics * 3.4.2 2017-10-06
#> grDevices * 3.4.2 2017-10-06
#> htmltools 0.3.6 2017-04-28
#> knitr 1.17 2017-08-10
#> magrittr 1.5 2014-11-22
#> memoise 1.1.0 2017-10-26
#> methods * 3.4.2 2017-10-06
#> pillar 0.0.0.9000 2017-11-29
#> pkgconfig 2.0.1 2017-03-21
#> purrr 0.2.4.9000 2017-11-02
#> R6 2.2.2 2017-06-17
#> Rcpp 0.12.14 2017-11-23
#> rlang * 0.1.4.9000 2017-12-17
#> rmarkdown 1.6.0.9004 2017-09-23
#> rprojroot 1.2 2017-01-16
#> stats * 3.4.2 2017-10-06
#> stringi 1.1.5 2017-04-07
#> stringr 1.2.0 2017-02-18
#> tibble 1.3.4.9003 2017-11-29
#> tidyselect 0.2.3 2017-11-06
#> tools 3.4.2 2017-10-06
#> utils * 3.4.2 2017-10-06
#> withr 2.1.0.9000 2017-11-29
#> yaml 2.1.14 2016-11-12
#> source
#> CRAN (R 3.4.0)
#> CRAN (R 3.4.0)
#> local
#> CRAN (R 3.4.0)
#> CRAN (R 3.4.0)
#> local
#> local
#> CRAN (R 3.4.1)
#> CRAN (R 3.4.0)
#> Github (tidyverse/dplyr@85e31dd)
#> CRAN (R 3.4.0)
#> cran (@1.2.0)
#> local
#> local
#> CRAN (R 3.4.0)
#> cran (@1.17)
#> CRAN (R 3.4.0)
#> Github (hadley/memoise@d63ae9c)
#> local
#> Github (r-lib/pillar@5a082e1)
#> CRAN (R 3.4.0)
#> local
#> CRAN (R 3.4.0)
#> CRAN (R 3.4.3)
#> Github (tidyverse/rlang@cc7587c)
#> Github (DavisVaughan/rmarkdown@f85ba35)
#> CRAN (R 3.4.0)
#> local
#> CRAN (R 3.4.0)
#> CRAN (R 3.4.0)
#> Github (tidyverse/tibble@60281b3)
#> cran (@0.2.3)
#> local
#> local
#> Github (jimhester/withr@fe81c00)
#> CRAN (R 3.4.0)
Thanks, @DavisVaughan. 馃憤 cc @lionel-
Please pump tidyverse's minimum version requirement of rlang so that install.packages("tidyverse") solves this.
@michaellevy the problem with that is that it's not a minimum version issue, it's a _matching_ version issue with dplyr and rlang. (See @DavisVaughan's code above). That's not to say that it doesn't have a solution, just that install.packages("tidyverse") (having the CRAN version), would suffer with a newer (i.e. the dev version of) rlang.
I have set rlang >= 0.1.6, this should at least resolve the case where users install the development version of dplyr.
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/
Most helpful comment
I've had this problem recently too. John is correct.
This is likely a non-issue though, just something to be aware of. Just tell people to be consistent in their use of dev / CRAN versions of dplyr & rlang. Looks like it gets fixed by using
tidyselect::vars_rename()inrename()rather thanrename_vars().Works - CRAN dplyr & rlang
Fails - CRAN dplyr, but dev rlang
Works - dev dplyr & rlang