library(tidyverse)でtidyverseに決断的ダイブ!

これめっちゃ便利なのでは…

tidyverse(a.k.a. hadleyverse)のパッケージを一気にインストールしてくれるパッケージです。

# たぶん来週からはinstall.packages()でいいはず
devtools::install_github("hadley/tidyverse")
#> Downloading GitHub repo hadley/tidyverse@master
#> from URL https://api.github.com/repos/hadley/tidyverse/zipball/master
#> Installing tidyverse
#> Installing 1 package: forcats
#> Installing package into ‘C:/Users/user1/Documents/R/win-library/3.3’
#> (as ‘lib’ is unspecified)
#> trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/forcats_0.1.0.zip'
#> Content type 'application/zip' length 152516 bytes (148 KB)
#> downloaded 148 KB
#> 
#> package ‘forcats’ successfully unpacked and MD5 sums checked
#> 
#> The downloaded binary packages are in
#>  C:\Users\user1\AppData\Local\Temp\Rtmpkx2CYg\downloaded_packages
#> Installing 1 package: haven
#> Installing package into ‘C:/Users/user1/Documents/R/win-library/3.3’
#> (as ‘lib’ is unspecified)
#> trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.3/haven_0.2.1.zip'
#> Content type 'application/zip' length 671595 bytes (655 KB)
#> downloaded 655 KB
#> 
#> package ‘haven’ successfully unpacked and MD5 sums checked

すでにインストールされているやつもtidyverse::tidyverse_update()すればアップデートしてくれます。

tidyverse::tidyverse_update()
#> The following packages are out of date:
#>  * Rcpp (0.12.6 -> 0.12.7)
#> Update now?
#> 
#> 1: Yes
#> 2: No
#> 
#> Selection: 1
#> package ‘Rcpp’ successfully unpacked and MD5 sums checked
#> Warning: cannot remove prior installation of package ‘Rcpp’

…ん? なんかwarningが出ている? まあとりあえず気にせず先に進みます。

library(tidyverse)するとtidyverseにあるパッケージをだいたい読み込んでくれます。

library(tidyverse)
#> Loading tidyverse: ggplot2
#> Loading tidyverse: tibble
#> Loading tidyverse: tidyr
#> Loading tidyverse: readr
#> Loading tidyverse: purrr
#> Loading tidyverse: dplyr
#> Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : 
#>   there is no package called ‘Rcpp’
#> Error : .onAttach failed in attachNamespace() for 'tidyverse', details:
#>   call: NULL
#>   error: package or namespace load failed for ‘ggplot2’
#> Error: package or namespace load failed for ‘tidyverse’

なんだこのエラーは…

よく分かりませんが、決断的にtidyverseにダイブしてみたものの、私ではカラテが足りなくて環境が壊れてしまいました…(Rcppとggplot2をinstall.packages()すれば直る)。インストールは問題なさそうですが、tidyverse_update()には気を付けたほうがよさそうです。

あと、libraryしたときはインストールされたパッケージをぜんぶ読み込んでくれるわけじゃないので注意。たとえばstringrとかはありません。うーん?

library(tidyverse)
#> Loading tidyverse: ggplot2
#> Loading tidyverse: tibble
#> Loading tidyverse: tidyr
#> Loading tidyverse: readr
#> Loading tidyverse: purrr
#>  Loading tidyverse: dplyr
#>  Use suppressPackageStartupMessages() to eliminate package startup messages.
#>  Conflicts with tidy packages -------------------------------------------------------------------------------------------------------------
#>  filter(): dplyr, stats
#>  lag():    dplyr, stats

cat(sort(loadedNamespaces()), sep = "\n")
#> assertthat
#> base
#> colorspace
#> datasets
#> DBI
#> dplyr
#> ggplot2
#> graphics
#> grDevices
#> grid
#> gtable
#> magrittr
#> methods
#> munsell
#> plyr
#> purrr
#> R6
#> Rcpp
#> readr
#> scales
#> stats
#> tibble
#> tidyr
#> tidyverse
#> tools
#> utils