简体   繁体   English

安装程序不会将包复制到新版本的 R

[英]installr does not copy over packages to new version of R

I recently used the package to update my version of R (from 3.6.2 to 4.0.0).我最近使用安装来更新我的 R 版本(从 3.6.2 到 4.0.0)。 The update was successful, and I have confirmed using print(R.version) .更新成功,我已确认使用print(R.version) However, my packages from the old version of R have not copied over to the new version, despite me following these steps to the letter.然而,我的旧版本 R 的包并没有复制到新版本,尽管我严格执行了这些步骤。 I have also tried to run copy.packages.between.libraries(ask = T) to copy the packages over.我还尝试运行copy.packages.between.libraries(ask = T)来复制包。 Both times returned No packages to copy. Goodbye:)两次都返回No packages to copy. Goodbye:) No packages to copy. Goodbye:) , despite me being unable to load any of the packages previously installed on the old version. No packages to copy. Goodbye:) ,尽管我无法加载以前安装在旧版本上的任何软件包。

This is because updating from R 3.6.x to 4.x requires that you reinstall all packages (see the news ).这是因为从 R 3.6.x 更新到 4.x 需要您重新安装所有软件包(请参阅新闻)。

The best way I found of doing this is:我发现这样做的最好方法是:

  1. get your old packages获取您的旧包裹
    old_packages <- installed.packages(lib.loc = "/home/johannes/R/x86_64-pc-linux-gnu-library/3.6/")

Of course, you have to change the path to the one where your packages live.当然,您必须将路径更改为您的包所在的路径。 Simply use .libPaths() and if you've already installed the new R version, replace the 4.0 with 3.6 .只需使用.libPaths() ,如果您已经安装了新的 R 版本,请将4.0替换为3.6

  1. check the old against the already installed packages:根据已安装的软件包检查旧的:

     new_packages <- installed.packages() missing_df <- as.data.frame(old_packages[,old_packages[, "Package"] %in% new_packages[, "Package"], ])
  2. install missing packages (use multiple cores for extra speed)安装缺少的软件包(使用多个内核来提高速度)

    install.packages(missing_df$Package, Ncpus = 3)

I wrote this up on my blog some time ago here , but these are the essential steps and you should be good to go.我前段时间在我的博客上写这个,但这些是必不可少的步骤,你应该对 go 很好。

If you have a look at the source code of copy.packages.between.libraries (just type F2 when your mouse pointer is on the function name), you find the following commands:如果您查看copy.packages.between.libraries的源代码(当您的鼠标指针位于 function 名称上时只需键入F2 ),您会发现以下命令:

library(installr)

(installed_R_folders <- get.installed.R.folders())
#>                   4.0.3                   4.0.2 
#> "C:/PROGRA~1/R/R-4.0.3" "C:/PROGRA~1/R/R-4.0.2"
(installed_R_folders_TABLE <- data.frame(R_version = names(installed_R_folders), 
                                        Folder = installed_R_folders))
#>       R_version                Folder
#> 4.0.3     4.0.3 C:/PROGRA~1/R/R-4.0.3
#> 4.0.2     4.0.2 C:/PROGRA~1/R/R-4.0.2
(from <- installed_R_folders[2])
#>                   4.0.2 
#> "C:/PROGRA~1/R/R-4.0.2"
(to <- installed_R_folders[1])
#>                   4.0.3 
#> "C:/PROGRA~1/R/R-4.0.3"
(from_library <- file.path(from, "library"))
#> [1] "C:/PROGRA~1/R/R-4.0.2/library"
(to_library <- file.path(to, "library"))
#> [1] "C:/PROGRA~1/R/R-4.0.3/library"
(packages_in_the_from_library <- list.files(from_library))
#>  [1] "base"         "boot"         "class"        "cluster"      "codetools"   
#>  [6] "compiler"     "datasets"     "foreign"      "graphics"     "grDevices"   
#> [11] "grid"         "KernSmooth"   "lattice"      "MASS"         "Matrix"      
#> [16] "methods"      "mgcv"         "nlme"         "nnet"         "parallel"    
#> [21] "rpart"        "spatial"      "splines"      "stats"        "stats4"      
#> [26] "survival"     "tcltk"        "tools"        "translations" "utils"
(packages_in_the_to_library <- list.files(to_library))
#>  [1] "base"         "boot"         "class"        "cluster"      "codetools"   
#>  [6] "compiler"     "datasets"     "foreign"      "graphics"     "grDevices"   
#> [11] "grid"         "KernSmooth"   "lattice"      "MASS"         "Matrix"      
#> [16] "methods"      "mgcv"         "nlme"         "nnet"         "parallel"    
#> [21] "rpart"        "spatial"      "splines"      "stats"        "stats4"      
#> [26] "survival"     "tcltk"        "tools"        "translations" "utils"
(packages_to_NOT_move <- unname(installed.packages(priority = "high")[,"Package"]))
#>  [1] "codetools"  "base"       "boot"       "class"      "cluster"   
#>  [6] "codetools"  "compiler"   "datasets"   "foreign"    "graphics"  
#> [11] "grDevices"  "grid"       "KernSmooth" "lattice"    "MASS"      
#> [16] "Matrix"     "methods"    "mgcv"       "nlme"       "nnet"      
#> [21] "parallel"   "rpart"      "spatial"    "splines"    "stats"     
#> [26] "stats4"     "survival"   "tcltk"      "tools"      "utils"
(packages_to_NOT_move <- c(packages_to_NOT_move, packages_in_the_to_library))
#>  [1] "codetools"    "base"         "boot"         "class"        "cluster"     
#>  [6] "codetools"    "compiler"     "datasets"     "foreign"      "graphics"    
#> [11] "grDevices"    "grid"         "KernSmooth"   "lattice"      "MASS"        
#> [16] "Matrix"       "methods"      "mgcv"         "nlme"         "nnet"        
#> [21] "parallel"     "rpart"        "spatial"      "splines"      "stats"       
#> [26] "stats4"       "survival"     "tcltk"        "tools"        "utils"       
#> [31] "base"         "boot"         "class"        "cluster"      "codetools"   
#> [36] "compiler"     "datasets"     "foreign"      "graphics"     "grDevices"   
#> [41] "grid"         "KernSmooth"   "lattice"      "MASS"         "Matrix"      
#> [46] "methods"      "mgcv"         "nlme"         "nnet"         "parallel"    
#> [51] "rpart"        "spatial"      "splines"      "stats"        "stats4"      
#> [56] "survival"     "tcltk"        "tools"        "translations" "utils"
(ss_packages_to_NOT_move_from <- packages_in_the_from_library %in% 
  packages_to_NOT_move)
#>  [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> [16] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
(ss_packages_to_YES_move_from <- !ss_packages_to_NOT_move_from)
#>  [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> [25] FALSE FALSE FALSE FALSE FALSE FALSE
(packages_to_YES_move_from <- packages_in_the_from_library[ss_packages_to_YES_move_from])
#> character(0)

Which comes to the conclusion there's no difference between the packages of the different R installations and leads to:得出的结论是,不同 R 安装的软件包之间没有区别,并导致:

No packages to copy.没有要复制的包。 Goodbye:)再见:)

However, if you look at .libPaths() , you see that get.installed.R.folders is missing the packages you installed on your own user's library:但是,如果您查看.libPaths() ,您会发现get.installed.R.folders缺少您在自己用户的库中安装的包:

.libPaths()
[1] "C:/Users/User/Documents/R/win-library/4.0"
[2] "C:/Program Files/R/R-4.0.3/library"

So default behaviour of installr is missing all the packages you installed after R installation:因此,安装程序的默认行为缺少您在installr安装后安装的所有软件包:

packages <- as.data.frame(utils::installed.packages())
head(packages[is.na(packages$Priority),c("Package","LibPath")])

arrow                               arrow C:/Users/User/Documents/R/win-library/4.0
arules                             arules C:/Users/User/Documents/R/win-library/4.0
arulesViz                       arulesViz C:/User/User/Documents/R/win-library/4.0
ash                                   ash C:/Users/User/Documents/R/win-library/4.0
askpass                           askpass C:/Users/User/Documents/R/win-library/4.0
assertive                       assertive C:/Users/User/Documents/R/win-library/4.0
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM