从CRAN镜像中安装具有依赖关系的本地R包 [英] Install a local R package with dependencies from CRAN mirror

查看:656
本文介绍了从CRAN镜像中安装具有依赖关系的本地R包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个R包,即我有mypackage.tar.gz文件。这个软件包取决于几个其他软件包,可以从任何CRAN镜像下载和安装。



现在我想在尚未安装依赖关系的系统上安装此软件包,我希望在安装我的软件包时会自动下载和安装依赖项。



我试过:

  install.packages(mypackage.tar.gz,type =source,dependencies = TRUE,repos =http://a.cran.mirror)

,但它会搜索 mypackage.tar.gz 镜像(显然它没有找到),而如果我设置 repos = NULL 它正确地尝试安装本地包文件(如文档),但显然它没有找到依赖项包。



所以我的问题是:有没有办法执行混合安装(具有在线依赖项的本地包)或唯一的方法做是手动安装所有依赖项?

解决方案

如果您已经安装了本地软件包,您应该可以使用工具中的几个功能来安装依赖项CRAN:

  library('tools')
installFoundDepends(pkgDepends('mypackage',local = FALSE)$ Found )

注意:您可以传递参数(如 repos )通过 installFoundDepends install.packages



您还可以使用 pkgDepends 输出中的依赖元素直接传递到安装。包

  install.packages(pkgDepends('mypackage')$ Depends)

更新:显然无法使用 dependencies = FALSE 。这似乎很奇怪,因为您可以从存储库中为远程软件包执行此操作。原因(查看源代码)是 if(is.null(repos)& missing(contriburl)),安装通过系统调用来处理 R CMD INSTALL ,它没有与依赖关系相关的参数。


I have built an R package, i.e. I have the mypackage.tar.gz file. This package depends on several other packages, all downloadable and installable from any CRAN mirror.

Now I want to install this package on a system where the dependencies are not yet installed, and I would like that the dependencies will be downloaded and installed automatically when I install my package.

I tried:

install.packages("mypackage.tar.gz",type="source",dependencies=TRUE,repos="http://a.cran.mirror")

but it searches for mypackage.tar.gz on the mirror (and obviously it does not find), while if I set repos=NULL it correctly tries to install the local package file (as documented), but obviously it does not find the dependencies packages.

So my question is: is there a way to perform a 'mixed' installation (local package with online dependencies) or the only way to do is to manually install all the dependencies?

解决方案

If you already have installed your local package, you should be able to use a couple functions in tools to install the dependencies from CRAN:

library('tools')
installFoundDepends(pkgDepends('mypackage', local = FALSE)$Found)

Note: You can pass args (like repos) through installFoundDepends to install.packages.

You can also use the Depends element from the pkgDepends output to pass directly to install.packages:

install.packages(pkgDepends('mypackage')$Depends)

UPDATE: Apparently it is not possible to install a local package with dependencies=FALSE. This seems odd, since you can do that for a remote package from a repository. The reason (looking at the source code) is that if(is.null(repos) & missing(contriburl)), installation is handled via system calls to R CMD INSTALL, which has no dependency-related arguments.

这篇关于从CRAN镜像中安装具有依赖关系的本地R包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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