简体   繁体   English

从本地存储库安装 R 包时出现问题

[英]problems installing R packages from a local repository

I've created a local repository of several r packages with all their dependency - that is a directory names PACKAGES under which there many zip files for the packages.我已经创建了几个 r 包及其所有依赖项的本地存储库 - 这是一个目录名称 PACKAGES ,在该目录下有许多 zip 包文件。

I try to install a package using:我尝试使用以下方法安装 package:

install.packages("dplyr",repos="path_to_repos",type="source")

and keep getting errors:并不断收到错误:

cannot open compressed file path_to_repos/src/contrib/PACKAGES, probable cause "permission denied"

I am able to install packages from the same directory by choosing the files one by one - but that's not practical due to dependencies.我可以通过一一选择文件来从同一目录安装软件包 - 但由于依赖关系,这不切实际。

I'm working on windows 10, and run as administrator.我正在研究 windows 10,并以管理员身份运行。 could not figure out what might be the cause of the permission error could be.无法弄清楚权限错误的原因可能是什么。

Any insight?有什么见解吗?

If I understand correctly, you've created a directory called "PACKAGES", which appears to be the problem.如果我理解正确,您已经创建了一个名为“PACKAGES”的目录,这似乎是问题所在。 All your files should go in the "contrib" directory.您的所有文件都应在“contrib”目录中的 go 中。

Once you've added package files to the "contrib" directory, you can use the setRepositories function from the utils package to create the repository.将 package 文件添加到“contrib”目录后,您可以使用setRepositories工具 ZEFE90A8E604A7C840E88D03A67F6B7DZ 中的setRepositories function 来创建存储库。 I'd recommend adding the following code to your .Rprofile for a local repository:我建议将以下代码添加到本地存储库的.Rprofile中:

utils::setRepositories(ind = 0, addURLs = c(WORK = "file://<your higher directories>/R"))

After editing your.Rprofile, restart R.编辑完你的.Rprofile,重启R。

ind = 0 will indicate that you only want the local repository. ind = 0表示您只想要本地存储库。 Additional repositories can be included in the addURLs = option and are comma separated within the character vector.附加存储库可以包含在addURLs =选项中,并在字符向量中以逗号分隔。

Next, create the repository index with the following code:接下来,使用以下代码创建存储库索引:

tools::write_PACKAGES("/<your higher directories>/R/src/contrib", verbose = TRUE) 

This will generate the PACKAGE files that serve as the repository index.这将生成用作存储库索引的 PACKAGE 文件。

To see what packages are in your repository, run the following code and take a look at the resulting data frame: my_packages <- available.packages()要查看存储库中有哪些包,请运行以下代码并查看生成的数据框: my_packages <- available.packages()

At this point, you can install packages from the repo without referencing the entire path to the package installation file.此时,您可以从 repo 安装包,而无需参考 package 安装文件的整个路径。 For example, to install the dplyr package, you could run the following:例如,要安装dplyr package,您可以运行以下命令:

install.packages("dplyr", dependencies = TRUE)

If you want to take it a step further and manage a changing repository, you could install and use the miniCRAN package.如果您想更进一步并管理不断变化的存储库,您可以安装和使用miniCRAN package。 Otherwise, you'll need to execute the write_PACKAGES function whenever your repository changes.否则,每当您的存储库更改时,您都需要执行write_PACKAGES function。

After installing the miniCRAN package, you can execute the following code to create the miniCRAN repo:安装miniCRAN package 后,您可以执行以下代码来创建miniCRAN 存储库:

 my_packages <- available.packages()

 miniCRAN::makeRepo(
  pkgs = my_packages[,1, 
  path = "/<your higher directories>/R",
  repos = getOption("repos"), 
  type = "source",
  Rversion = R.version, 
  download = TRUE, 
  writePACKAGES = TRUE,
  quiet = FALSE
 )

You only need to execute the code above once for each repo.您只需要为每个 repo 执行一次上面的代码。

Then, check to make sure each miniCRAN repo has been created.然后,检查以确保已创建每个 miniCRAN 存储库。 You only need to do this once for each repo:您只需为每个 repo 执行一次:

 pkgAvail(
  repos = getOption("repos"),
  type = "source",
  Rversion = R.version,
  quiet = FALSE
 )

Whenever new package files are placed into the local repo you can update the local repo's index as follows:每当将新的 package 文件放入本地存储库时,您可以按如下方式更新本地存储库的索引:

miniCRAN::updateRepoIndex("/<your higher directories>/R/")

Finally, as an optional step to see if the new package is in the index, create a data frame of the available packages and search the data frame:最后,作为查看新 package 是否在索引中的可选步骤,创建可用包的数据框并搜索数据框:

my_packages <- available.packages(repos = "file://<your higher directories>/R/")

This approach has worked pretty well for me, but perhaps others have comments and suggestions that could improve upon it.这种方法对我来说效果很好,但也许其他人有可以改进的意见和建议。

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

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