离线安装 R 包和依赖项 [英] Offline install of R package and dependencies

查看:99
本文介绍了离线安装 R 包和依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我需要在没有互联网连接的 (Linux) 机器上安装一些软件包.假设我下载了一份 cran 并将其刻录到我带到离线位置的 DVD 上:

Suppose I need to install a number of packages on a (Linux) machine that does not have an internet connection. Let's say that I downloaded a copy of cran and burned it on a DVD that I bring to the offline location:

wget ftp://cran.r-project.org/pub/R/src/contrib/*.tar.gz

我什至可以添加一个 PACKAGES 文件,其中包含所有源包及其依赖项的概述:

I can even add a PACKAGES file that contains an overview of all the source packages and their dependencies:

library(tools)
write_PACKAGES()

我如何离线使用它来安装源包,以便从本地文件解析和安装依赖项?例如,有人想要安装包 ggplot2,它具有相当深的依赖结构.假设 ggplot2 的源包及其所有依赖项在当前工作目录中作为源包可用.如果我这样做:

How could I use this offline to install a source package in such a way that dependencies are resolved and installed from the local files as well? For example, someone wants to install package ggplot2, which has a fairly deep dependency structure. Assume the source package of ggplot2 and all of its dependencies are available as source packages in the current working directory. If I do:

install.packages("ggplot2_0.9.1.tar.gz", repos=NULL)

这会导致错误,因为根本没有解析依赖项.或者:

This results in an error, because the dependencies are not resolved at all. Alternatively:

install.packages(list.files(pattern="*.tar.gz"), repos=NULL)

然而,这也忽略了依赖结构,并尝试按字母顺序安装包,这也会失败.

However this also ignores the dependency structure, and tries to install packages in alphabetical order, which will also fail.

我查看了 available.packagescontrib.url,但我找不到从本地文件安装源包的示例,包括它的依赖项.

I looked into available.packages and contrib.url but I just can't find an example of installing a source package from a local file including it's dependencies.

推荐答案

Joshua Ulrich 在对问题的评论中给出了正确答案:

The correct answer was given by Joshua Ulrich in the comment on the question:

关键是在reposcontriburl 的参数前面加上file://.所以在 Unixy 系统中可以这样做:

The key is prefixing the argument to either repos or contriburl with file://. So in Unixy systems one could do:

install.packages("ggplot2", contriburl="file:///path/to/packages/")

这假设所有必需的源包以及 PACKAGES 索引文件在 /path/to/packages 中可用.如果不存在 PACKAGES 文件,则应首先使用:

This assumes that all required source packages, as well as a PACKAGES index file is available in /path/to/packages. If no PACKAGES file is present, this should be generated first using:

library(tools)
write_PACKAGES("/path/to/packages/")

它将生成在此目录中找到的所有源包的索引.请注意,在示例中,file: 前缀后面有 3 个斜杠.第三个斜杠表示相对于文件系统根目录的路径.

which will generate an index of all source packages found in this directory. Note that in the example, there are 3 slashes behind the file: prefix. The third slash indicates a path relative to the root of the file system.

reposcontriburl 参数之间的区别在于 repos 会附加另一个 /src/contrib 到指定的路径,因为这通常是源包位于官方 CRAN 存储库镜像的位置.

The difference between the repos and contriburl argument is that repos will append another /src/contrib to the path specified, as this is usually where source packages are located on an official CRAN repository mirror.

这篇关于离线安装 R 包和依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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