简体   繁体   English

如何迁移 Rstudio 文件和安装的包(按版本到新计算机)

[英]How to migrate Rstudio files and installed packages ( by version to a new computer )

Good afternoon !下午好 !

I need to migrate a full installation of Rstudio to a new computer.我需要将 Rstudio 的完整安装迁移到新计算机。

My old computer contains two versions of Rstudio.我的旧电脑包含两个版本的 Rstudio。

I had tried the following code:我试过以下代码:

installed <- as.data.frame(installed.packages())

write.csv(installed, 'installed_previously.csv')

installedPreviously <- read.csv('installed_previously.csv')

baseR <- as.data.frame(installed.packages())

toInstall <- setdiff(installedPreviously, baseR)

What I need to is to list the installed versions of Rstudio ( with their associated installed packages ).我需要列出 Rstudio 的安装版本(及其相关的安装包)。 After that, I need to copy all R code files.之后,我需要复制所有 R 代码文件。

I'm searching a script that automate this migration.我正在搜索自动执行此迁移的脚本。

Thank you for help !谢谢你的帮助 !

I suppose the first thing to do would be to make sure that the set of currently installed packages is up-to-date.我想首先要做的是确保当前安装的软件包集是最新的。 Then build a target string of package names.然后构建 package 名称的目标字符串。 This would be one possible methods.这将是一种可能的方法。

  update.packages(checkBuilt=TRUE, ask=FALSE)  #check spelling of arguments
  new_pacs <- paste( setdiff( installedPreviously$Package, baseR$Package), 
                       collapse=",")
  install.packages( new_pacs, dependencies=TRUE)

If this is a really big set of packages then it's very possible that you will need to repeat steps 2 and 3 a few times.如果这是一组非常大的软件包,那么您很可能需要重复步骤 2 和 3 几次。 The management of dependencies is not sophisticated, and it's likely that there will be packages which have "second cousins" that are not named in the DESCRIPTION files of package being installed at the beginning.依赖项的管理并不复杂,很可能会有一些包有“第二代”,这些包在开始安装的 package 的说明文件中没有命名。 It's even possible that you might want to limit the number of package installed as a group to say 30 at a time.您甚至可能希望将作为一个组安装的 package 的数量限制为一次 30 个。 That would allow you to identify some of the missing but critical packages early in the process.这将允许您在流程的早期识别一些缺失但关键的包。

Another method (which seems cumbersome but was effective) used in the past is to simply copy the entire contents of an existing library directory to the new directory (excluding any that are already there by refusing to overwrite.) And then run the update.packages call above.过去使用的另一种方法(看起来很麻烦但很有效)是简单地将现有库目录的全部内容复制到新目录(通过拒绝覆盖而排除已经存在的任何内容。)然后运行update.packages调用上面。

Yet another method would be to depend on the Packrat system.还有一种方法是依赖于 Packrat 系统。 It's now built into the Rstudio project management tools.它现在已内置到 Rstudio 项目管理工具中。

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

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