如何安装不在 conda 存储库中的 R 包?

How to install R-packages not in the conda repositories?

我正在使用 Anaconda 来管理我的 R 安装。它适用于 Anaconda 提供的 R 通道中可用的包,但我在安装 Anaconda 存储库中不包含的包时遇到了麻烦。

我尝试了几种不同的方法,下面列出了所有方法及其错误输出。

1。 install.packages('rafalib')

建议在这里工作。我的 .libPaths() 指向 '/home/user/anaconda2/lib/R/library'.

输出:

--- Please select a CRAN mirror for use in this session ---
Error in download.file(url, destfile = f, quiet = TRUE) : 
  unsupported URL scheme
Error: .onLoad failed in loadNamespace() for 'tcltk', details:
  call: fun(libname, pkgname)
  error: Can't find a usable init.tcl in the following directories: 
    /opt/anaconda1anaconda2anaconda3/lib/tcl8.5 ./lib/tcl8.5 ./lib/tcl8.5 ./library ./library ./tcl8.5.18/library ./tcl8.5.18/library

This probably means that Tcl wasn't installed properly.

我从 c​​onda 频道 r-old 安装了 tcl,但 install.packages() 仍然抛出相同的错误消息。

2。 options(menu.graphics=FALSE) 然后 install.packages('rafalib')

我得到了镜像列表并选择了一个。

输出:

Selection: 15
trying URL 'http://cran.utstat.utoronto.ca/src/contrib/rafalib_1.0.0.tar.gz'
Content type 'application/x-gzip' length 11798 bytes (11 KB)
==================================================
downloaded 11 KB

sh: symbol lookup error: sh: undefined symbol: rl_signal_event_hook

The downloaded source packages are in
        ‘/tmp/Rtmphwpta0/downloaded_packages’
Warning message:
In install.packages("rafalib") :
  installation of package ‘rafalib’ had non-zero exit status

2和3都来自Disable/suppress tcltk popup for CRAN mirror selection in R

3。在 ~/.Rprofile

中设置镜像

在尝试 install.packages() 之前,我将以下内容添加到我的 ~/.Rprofile

## Default repo
local({r <- getOption("repos");
       r["CRAN"] <- "http://cran.us.r-project.org"; 
       options(repos=r)})

输出:

trying URL 'http://cran.us.r-project.org/src/contrib/rafalib_1.0.0.tar.gz'
Content type 'application/x-gzip' length 11798 bytes (11 KB)
==================================================
downloaded 11 KB

sh: symbol lookup error: sh: undefined symbol: rl_signal_event_hook

The downloaded source packages are in
        ‘/tmp/RtmppIz9rT/downloaded_packages’
Warning message:
In install.packages("rafalib") :
  installation of package ‘rafalib’ had non-zero exit status

4。将下载方式设置为 'curl' 或 'wget'.

同时保留新的 ~/.Rprofile configuration。我想这不是必需的,因为包现在似乎可以正常下载,但我测试了它以防万一。

输出:

sh: symbol lookup error: sh: undefined symbol: rl_signal_event_hook
Warning in download.packages(pkgs, destdir = tmpd, available = available,  :
  download of package ‘rafalib’ failed
Warning message:
In download.file(url, destfile, method, mode = "wb", ...) :
  download had nonzero exit status

5。手动 download of rafalib

install.packages('../Downloads/rafalib_1.0.0.tar.gz', repos=NULL, type='source')

输出:

sh: symbol lookup error: sh: undefined symbol: rl_signal_event_hook
Warning message:
In install.packages("../Downloads/rafalib_1.0.0.tar.gz", repos = NULL,  :
  installation of package ‘../Downloads/rafalib_1.0.0.tar.gz’ had non-zero exit status

6。从 rafalib

构建一个 conda 包

我为此 打开了一个单独的问题。简而言之,它抱怨缺少我已经安装的依赖项。 更新 我遇到了依赖性问题,现在我陷入了与其他方法相同的 rl_signal_event_hook-错误。

7。 sudo ln /usr/lib/libncursesw.so.6 /usr/lib/libncursesw.so.5

根据 https://github.com/conda/conda/issues/1679,但它没有解决我的问题。


看来我现在可以正常下载包了,但是安装失败了。我之前在 Jupyter Notebook 中使用带有 irkernel 的 R 时看到错误消息 sh: symbol lookup error: sh: undefined symbol: rl_signal_event_hook,但它从未妨碍我的工作。当 运行 python 通过 anaconda 时,我从未见过与该错误消息相关的任何内容。

我没主意了。有谁知道我如何安装 anaconda 未提供的 R 包,例如 rafalibswirl

我正在 Linux(Antergos,Arch 衍生产品),内核为 4.4.5-1-ARCH。


更新 2016/04/15

有一些related discussion in this thread. I have tried to get around this error by installing different versions of ncurses, including this patched version, and I have tried to link the readline libraries, as suggested here,但我一直运行进入同样的错误。在这一点上我很迷茫,任何解决这个问题的帮助将不胜感激。

详细post 管理在 Anaconda R 中和不在 Anaconda R 中的包:http://ihrke.github.io/conda.html

本质上就是使用命令:

conda skeleton cran <package_name>
conda build <package_name>

如果包有依赖项,但 Anaconda 中没有:

conda skeleton cran <dependency1>
conda skeleton cran <dependency2>
conda build <package_name>

基本上我同意 post 的说法,我不明白 install.packages() 如何与 Anaconda 一起工作。我似乎看到的是 Anaconda 创建了一个 R 环境,其中保留了从 install.packages() 安装的所有软件包。

每当我在 Jupyter 中使用 R 时,我都会使用这个环境,并且能够访问我用 install.packages()

安装的所有包

最后,我通过遵循 the approach recommended here 并将 anaconda 的 libreadline 符号链接到系统一来解决了 rl_event_hook 问题:

mv ~/anaconda3/lib/libreadline.s.6.2 ~/anaconda3/lib/libreadline.s.6.2.bak
ln -s /usr/lib/libreadline.so.6.3 ~/anaconda3/lib/libreadline.s.6.2

由于使用 install.packages() 从 Withing R 加载共享对象失败,我在安装一些重依赖 R 包时仍然遇到问题。但是,更简单的包工作正常,我可以获得大部分重依赖来自 anacondas R-repositories 的包。