有没有一种方法可以自动在R中重新安装软件包及其依赖项? [英] Is there a way to automate reinstalling packages and their dependencies in r?

查看:79
本文介绍了有没有一种方法可以自动在R中重新安装软件包及其依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在Rstudio上使用installR将R更新到版本4.0.0,并将其软件包的文件复制到R中的库文件中,目录为: C:\ Users \ Ibrahim \ Documents \R \ R-4.0.0 \ library

So I used installR on Rstudio to update R to version 4.0.0, and it copied the files of my packages into the library file in the R, the directory being: C:\Users\Ibrahim\Documents\R\R-4.0.0\library

每当我调用一个程序包(例如tidytext)时,它都会给我:

Whenever I'd call on a package, for example tidytext, it would give me:

library(tidytext)
Error: package or namespace load failed for ‘tidytext’:
 package ‘tidytext’ was installed before R 4.0.0: please re-install it 

然后我尝试安装它,它将给我:

And then I'd try installing it, and it would give me:

install.packages('tidytext')
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.0/tidytext_0.2.4.zip'
Content type 'application/zip' length 3008780 bytes (2.9 MB)
downloaded 2.9 MB

package ‘tidytext’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\Ibrahim\AppData\Local\Temp\Rtmpmo5Lza\downloaded_packages

再次调用将给出:

library(tidytext)
Error: package or namespace load failed for ‘tidytext’:
 package ‘tokenizers’ was installed before R 4.0.0: please re-install it

然后,我将继续安装下一个依赖项,并重新调用该程序包,直到最终生效.

And I would keep installing the next dependency and recalling the package until it would finally work.

我尝试使用发现的这段代码来自动执行此操作:

I tried to automate this with this code I found:

lib_loc <- "C:/Users/Ibrahim/Documents/R/R-4.0.0/library"
to_install <- unname(installed.packages(lib.loc = lib_loc)[, "Package"])
to_install
install.packages(pkgs = to_install)
install.packages(pkgs = to_install, dependencies=T, INSTALL_opts='--no-lock')

这将在目录中创建一堆.zip文件: C:\ Users \ Ibrahim \ AppData \ Local \ Temp \ Rtmpmo5Lza \ downloaded_pa​​ckages

And that would create a bunch of .zip files to the directory: C:\Users\Ibrahim\AppData\Local\Temp\Rtmpmo5Lza\downloaded_packages

但是一段时间后,它最终锁定,在初始/library目录中创建了一个名为00LOCK的文件夹/文件,并停止了该过程.

But after a while, it eventually locks, creating a folder/file called 00LOCK in the initial /library directory, and stop the process.

然后我将其删除,但是当我再次运行代码时,我想也许它会重做许多已经完成的文件,并且最终仍然会再次锁定.我做错什么了吗?有办法解决这个问题吗?手动执行是很痛苦的.我应该重新安装RStudio吗?我失去了希望.

And I would then delete it, but when I'd run the code again, I guess maybe it redoes many of the files already done, and still eventually locks again. Am I doing anything wrong? Is there a way I can fix this? It's a real pain to do it manually. Should I just reinstall RStudio? I'm losing hope.

推荐答案

将R升级到较新版本后,确实需要重新编译某些R软件包.这可能是您的情况.要重新安装和更新这些 old 软件包(即在R的早期版本下构建的软件包),您可以尝试在R控制台中运行以下代码:

Some R packages really need recompilation after upgrade of R to a newer version. This could be your case. To reinstall and update these old packages (i.e. packages built under an earlier version of R) you can try to run this code in R console:

update.packages(ask = FALSE,
                checkBuilt = TRUE)

ask 参数可防止R不断要求您确认每个软件包的每次更新,而 checkBuilt 参数用于重新安装在R的早期版本下构建的所有软件包.

The ask parameter prevents R from constantly asking you to confirm every update of every package, while the checkBuilt parameter is to reinstall all packages built under an earlier version of R.

有关更多信息,请参见文档或在RStudio的R控制台中键入?update.packages .希望这会有所帮助!

For more information see the documentation or type ?update.packages in your R console in RStudio. Hope this helps!

这篇关于有没有一种方法可以自动在R中重新安装软件包及其依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆