【问题标题】:Installing packages on R fails when loading .Rprofile加载 .Rprofile 时在 R 上安装包失败
【发布时间】:2013-08-14 19:42:51
【问题描述】:

当我尝试在 R 中安装软件包时,如果我的 .Rprofile 已加载,安装几乎总是会失败。但是,当我使用 --vanilla 标志加载 R 时,我可以毫无问题地安装软件包。这是有问题的 R 会话的输出。我认为困难与我在.Rprofile 中的.First() 函数或历史文件有关。 My Rprofile file is here.

$ install.packages("SuppDists")
Installing package into ‘/home/lmullen/R/x86_64-pc-linux-gnu-library/3.0’
(as ‘lib’ is unspecified)
trying URL 'http://cran.cnr.Berkeley.edu/src/contrib/SuppDists_1.1-9.tar.gz'
Content type 'application/x-gzip' length 140784 bytes (137 Kb)
opened URL
==================================================
downloaded 137 Kb

Loading required package: stats
Loading required package: sp
rgeos version: 0.2-19, (SVN revision 394)
 GEOS runtime version: 3.3.3-CAPI-1.7.4 
 Polygon checking: TRUE 

rgdal: version: 0.8-10, (SVN revision 478)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.9.0, released 2011/12/29
Path to GDAL shared files: /usr/share/gdal/1.9
Loaded PROJ.4 runtime: Rel. 4.7.1, 23 September 2009, [PJ_VERSION: 470]
Path to PROJ.4 shared files: (autodetected)
Error in .External2(C_loadhistory, file) : no history mechanism available
Calls: .First -> <Anonymous>
Execution halted

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

有谁知道问题出在哪里?

【问题讨论】:

  • 您是否尝试删除 .First 函数以查看是否有帮助?
  • 我也只建议在交互式会话中加载任何包 - 通常,我建议不要加载任何包,因为它会导致不可重现的代码
  • @Dason:我尝试删除 .First 函数,关于历史记录的错误消息消失了,但软件包仍然没有安装。
  • @hadley:感谢您的建议。我完全同意加载包。我总是通过带有 --vanilla 标志的非交互式会话运行代码。但我采纳了你的建议,将所有包加载移到了检查会话是否是交互式的函数中。

标签: r install.packages


【解决方案1】:

Henrik 在 R-devel 邮件列表中给了我答案:

使用

if (interactive()) utils::loadhistory(file = "~/.Rhistory")

应该可以解决您的问题。原因是install.packages() 在 turn 启动一个非交互式子 R 进程,该进程安装 包裹。当该进程加载您的启动文件时,它会失败,因为 该功能只能在交互模式下使用。

【讨论】:

【解决方案2】:

我发现了我的.Rprofile 中导致问题的行,但我不知道它们为什么会导致问题。 .First.Last 函数是:

.First <- function() {
  utils:::loadhistory(file = "~/.Rhistory")
  cat("\nSuccessfully loaded .Rprofile at", date(), "\n\n")
}

.Last <- function() {
  utils:::savehistory(file = "~/.Rhistory")
}

注释掉关于保存和加载历史记录的行让我安装包。

【讨论】:

  • 还是不知道是什么原因造成的?
  • 知道了,看我的回答
【解决方案3】:

在 Ubunto 中:

感谢@hugo-raguet,我从 R 外部安装它并且运行良好:

sudo apt-get -y install build-essential
sudo apt-get -y install r-cran-igraph

我相信以后在 R 中不需要安装 igraph

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-23
    • 1970-01-01
    • 2021-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多