仅下载包的源和所有依赖项 [英] Only download sources of a package and all dependencies
问题描述
我想知道是否有办法使用 install.packages()
或其他相关函数来执行以下操作:只下载源代码(即 tar.gz
文件)将指定包及其所有依赖项放入指定文件夹(在 Windows 上).
I am wondering if there's a way to use install.packages()
or other related functions to do the following: only download the sources (i.e. tar.gz
files) of the specified packages and all their dependencies into a specified folder (on Windows).
这样做的一个原因是:假设我有一个未启用互联网访问的 Linux 帐户.为了在 Linux 机器上安装软件包,我首先在我的 Windows 机器上下载所有需要的源,然后将它们 ftp 到 Linux 机器上,然后使用
One reason to do this is: say I have a Linux account that is not enabled for internet access. In order to install the packages on the Linux machine, I would first download all the needed sources on my Windows machine, then ftp them over to the Linux machine, and install them on the Linux machine using
install.packages('/home/me/R/Packages/blah.tar.gz', repos = NULL)
推荐答案
现在在 base R 附带的 tools 包中有更好的选择:package_dependencies()代码>.例如,请参阅来自@sebastian-c 的答案和此最近的问答,了解相关用例.强>
There are now better options for this in the tools package that comes with base R: package_dependencies()
. See for example, the Answer from @sebastian-c and this recent Q&A for a related use-case.
utils 包中有一个未导出的 getDependencies()
函数.我还没有研究过它是如何工作的,但是将它与@Dirk's Answer 结合起来应该可以帮助您完成大部分工作.
There is an unexported getDependencies()
function in the utils package. I haven't studied how it works, but combining that with @Dirk's Answer should get you most of the way there.
但基本上,您似乎会像这样使用它:
Basically though, it appears you use it like:
utils:::getDependencies(pkgs, dependencies, available, lib)
其中 pkgs
是要安装的软件包的字符向量,dependencies
是您想要的依赖类型(Depends、Enhances 等)的字符向量,available
是 available.packages()
的输出,lib
是评估依赖项的包的库位置.
where pkgs
is the character vector of packages to install, dependencies
is a character vector of types of dependencies (Depends, Enhances etc) that you want, available
is the output from available.packages()
and lib
is the library location for the packages within which dependencies are evaluated.
如果您调试 install.packages()
它基本上是在执行 getDependencies()
步骤,然后是 @Dirk 的 download.packages()
步骤在它真正开始安装之前.
If you debug install.packages()
it is basically doing the getDependencies()
step then @Dirk's download.packages()
step before it actually starts installing anything.
这篇关于仅下载包的源和所有依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!