迁移 R 库

发布于 2024-11-30 08:36:07 字数 1239 浏览 3 评论 0 原文

我想在 Linux 上将多个 R 库 (*) 从一个驱动器移动到另一个驱动器,并且想知道简单的移动是否可行且安全,或者我是否应该卸载并重新安装这些软件包。我意识到库的位置是通过 .libPaths() 标识的,并浏览了“R 安装和管理”手册以了解有关迁移库的信息,但没有看到推荐的过程。

我认为三个选项:

  1. 对所有非基础软件包运行 remove.packages() ,并通过 install.packages(lib = "/path/to/new/location" 重新安装)
  2. 使用 mv 移动库(目录)并使用符号链接指向新位置(并最终删除符号链接)
  3. 在 Linux 中使用 mv 命令批量移动目录并按照 R_HOME/etc/Rprofile.site 中的 .Library.site href="http://cran.r-project.org/doc/manuals/R-admin.html#Managing-libraries" rel="noreferrer">R 安装和管理手册

选项 #1 很生硬。选项#2应该可以工作,但似乎有点不合理。

#3 安全吗还是存在严重问题?我发现的问题是:目录权限以及任何包的设置存储绝对路径而不是相对路径的可能性(这似乎不合理且不必要)。

关于绝对路径的存储,我发现rJavaR_HOME的位置存储在一个名为run的文件中。这本身并不是一个库问题,但它表明一个包(而且是一个好的包)保留了绝对路径的私有副本。

(*) 有几个库和许多软件包。当然,只是移动了库(目录),但包可能会受到影响。


更新 1/澄清:只是澄清一下:我只是迁移库,而不是更改 R 版本或软件包版本。更新 R 或软件包可以单独完成,但问题只是移动库是否可行。看来,如果有必要更新或重新安装所有软件包以确保正确安装,那么该路径更类似于选项#1,而不是选项#3。

更新2:另一篇SO帖子的答案有一些关于如何在升级时避免此问题的好主意。我不会升级 R,但 Dirk Eddelbuettel 提出的不在 R 文件树中安装软件包的建议是明智的。

I'd like to move several R libraries (*) from one drive to another, on Linux, and would like to know whether a simple move is feasible and safe or if I should uninstall and reinstall the packages. I realize that the locations of libraries are identified via .libPaths() and have looked through the "R Installation and Administration" manual to find out about migrating libraries, but don't see a recommended process.

I perceive three options:

  1. Run remove.packages() for all of the non-base packages, and install anew via install.packages(lib = "/path/to/new/location").
  2. Move the libraries (directories) using mv and use symlinks to point to the new locations (and eventually remove the symlink)
  3. Use the mv command in Linux to move the directories wholesale and update .Library.site in R_HOME/etc/Rprofile.site, as suggested in the R Installation and Administration manual

Option #1 is blunt. Option #2 should work, but seems a bit unsound.

Is #3 safe or are there serious problems with it? The issues I've identified are: directory permissions and the possibility that any package's setup stores absolute paths rather than relative paths (which seems unsound and unnecessary).

Regarding the storage of absolute paths, I found that rJava stores the location of R_HOME in a file called run. This isn't a library problem per se, but it is one indication of a package (and a good package at that) keeping a private copy of an absolute path.

(*) There are several libraries and many scores of packages. Naturally, just the libraries (directories) are moved, but packages could be affected.


UPDATE 1 / Clarification: Just to clarify: I am only migrating libraries, not changing the version of R or the versions of the packages. Updating R or the packages may be done separately, but the question is just whether or not moving the libraries is feasible. It seems that if it is necessary to update or reinstall all packages in order to be sure things are installed correctly, then that is a path more akin to option #1 than option #3.

UPDATE 2: Answers to another SO post have some good ideas on how to avoid this problem when upgrading. I'm not upgrading R, but Dirk Eddelbuettel's suggestion of not installing packages in the filetree of R is wise.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不离久伴 2024-12-07 08:36:07

选项 #3(将旧库复制到新库)应该可以工作......但是当且仅当您运行:

update.packages(checkBuilt=TRUE)

以这种方式,需要为新版本重建的包将得到更新。通常情况下,新版本会添加要求(例如 2.14.x 中即将出现的 NAMESPACE 要求)。

编辑:看到这只是在躺椅上移动......如果你要移动任何基本的 R 安装,我将不再支持 #3。它在 Mac 上对我有用,但我没有在 R 安装和管理指南或 R 常见问题解答中看到它应该工作的承诺。您可以通过以下顺序完成#1(在各种条件下这可能是最安全的):

# In original installation, get the non-default package list:
save.pkg.list <- installed.packages()[is.na(installed.packages()[ , "Priority"]), 1]
save(save.pkg.list, file="pkglist.Rdata")
# If you want to use remove.packages() at this point it's fine. 
# Or just delete their directories.

使用新安装的 R 版本,并将 .Libpaths 设置为您的首选项(甚至相同的旧安装):

load("pkglist.Rdata")
install.packages(save.pkg.list)

只需将包移动到新库如果 R 可执行文件未更改可能会成功(假设您还更改了 .Libpaths),但我没有 Linux 安装来测试它或知道配置操作设置的任何指针将如何受到影响。

Option #3 (copying old library to new library) should work ... but if and only if you then run:

update.packages(checkBuilt=TRUE)

In this manner the packages that need to be rebuilt for new versions will get updated. It is often the case that new versions add requirements (such as the impending requirement in 2.14.x for NAMESPACEs).

Edit: Seeing this is just moving around the deck chairs .... I'm going to back off from endorsing #3 if you are moving any of the base R installation. It has worked for me in a Mac, but I have not seen a promise in the R Installation and Administration Guide or the R FAQ that it should work. You can accomplish #1 (which is probably safest in various conditions) by this sequence:

# In original installation, get the non-default package list:
save.pkg.list <- installed.packages()[is.na(installed.packages()[ , "Priority"]), 1]
save(save.pkg.list, file="pkglist.Rdata")
# If you want to use remove.packages() at this point it's fine. 
# Or just delete their directories.

With a freshly installed version of R with the .Libpaths set to your preferences (or even the same old installation):

load("pkglist.Rdata")
install.packages(save.pkg.list)

Just moving the packages to a new library if the R executables was not changed might succeed (assuming you also change the .Libpaths) but I do not have a Linux installation to test it or know how any pointers set by configure operations would be affected.

眉黛浅 2024-12-07 08:36:07

将接受的答案与 this 相结合,我找到了一个更简单的有效解决方案:

lib_loc <- "C:/Users/apdev/Documents/R/win-library/3.3"
to_install <- unname(installed.packages(lib.loc = lib_loc)[, "Package"])
to_install
remove.packages(to_install, lib="C:/Users/apdev/Documents/R/win-library/3.3")
install.packages(pkgs = to_install, lib="C:/Program Files/R/R-3.6.1/library")

Combining the accepted answer, with this one, I found a simpler solution that worked:

lib_loc <- "C:/Users/apdev/Documents/R/win-library/3.3"
to_install <- unname(installed.packages(lib.loc = lib_loc)[, "Package"])
to_install
remove.packages(to_install, lib="C:/Users/apdev/Documents/R/win-library/3.3")
install.packages(pkgs = to_install, lib="C:/Program Files/R/R-3.6.1/library")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文