Dplyr 0.3.0.2 rename () idiom is unstable when loading the reshape package

sessionInfo() # R version 3.1.1 (2014-07-10) # Platform: x86_64-apple-darwin10.8.0 (64-bit) # # attached base packages: # [1] stats graphics grDevices utils datasets methods base # # other attached packages: # [1] dplyr_0.3.0.2 # # loaded via a namespace (and not attached): # [1] assertthat_0.1 DBI_0.3.1 lazyeval_0.1.9 magrittr_1.0.1 parallel_3.1.1 Rcpp_0.11.3 # [7] tools_3.1.1 

when only dplyr 0.3.0.2 was loaded, the default work renamed the default.

 packageVersion("dplyr") # [1] '0.3.0.2' iris[1:10,] %>% rename(petal_length = Petal.Length) # Sepal.Length Sepal.Width petal_length Petal.Width Species # 1 5.1 3.5 1.4 0.2 setosa # 2 4.9 3.0 1.4 0.2 setosa 

when the library (reshape) was loaded, the idiom didn't seem to work

 # other attached packages: # [1] reshape_0.8.5 dplyr_0.3.0.2 # # loaded via a namespace (and not attached): # [1] assertthat_0.1 chron_2.3-45 data.table_1.9.5 DBI_0.3.1 lazyeval_0.1.9 # [6] magrittr_1.0.1 parallel_3.1.1 plyr_1.8.1 Rcpp_0.11.3 reshape2_1.4 # [11] stringr_0.6.2 tidyr_0.1 tools_3.1.1 iris[1:10,] %>% rename(petal_length = Petal.Length) # Error in rename(`iris[1:10, ]`, petal_length = Petal.Length) : # unused argument (petal_length = Petal.Length) 

and you need to resort to the code below

 iris[1:10,] %>% rename(c("Petal.Length" = "petal_length")) # Sepal.Length Sepal.Width petal_length Petal.Width Species # 1 5.1 3.5 1.4 0.2 setosa # 2 4.9 3.0 1.4 0.2 setosa 

This is mistake?

+6
source share
1 answer

If you have two or more downloaded packages that contain functions with the same name, you will need to use the double-column operator :: to get the version of the function from the package that was not the last downloaded package (I hope this makes sense).

Thus, in terms of these two packages, this means dplyr::rename() use the dplyr or reshape::rename() version to use the reshape version depending on the location of the packages in the search path.

Since you downloaded the reshape package after downloading the dplyr package, you need dplyr::rename() use the rename() function from the dplyr package. rename() independently sends to the reshape version in this case.

 iris[1:10,] %>% dplyr::rename(petal_length = Petal.Length) 

gotta do the trick.

+13
source

Source: https://habr.com/ru/post/976747/


All Articles