无法在 Linux 中安装 R tseries、quadprog、xts 包

cannot install R tseries, quadprog ,xts packages in Linux

我正在使用 R 版本 3.4.0

我正在尝试在 linux 机器上安装 tseries 包:

install.packages('https://cran.cnr.berkeley.edu/src/contrib/tseries_0.10-42.tar.gz',dependencies = TRUE,repos = NULL,type ="source")

It gives error:
ERROR: compilation failed for package 'xts'
* removing '/usr/lib64/R/library/xts'
ERROR: dependency 'xts' is not available for package 'TTR'
* removing '/usr/lib64/R/library/TTR'
ERROR: dependencies 'xts', 'TTR' are not available for package 'quantmod'
* removing '/usr/lib64/R/library/quantmod'
ERROR: dependencies 'quadprog', 'quantmod' are not available for package 'tseries'
* removing '/usr/lib64/R/library/tseries'

1: In install.packages("tseries", dependencies = TRUE) :
  installation of package 'quadprog' had non-zero exit status
2: In install.packages("tseries", dependencies = TRUE) :
  installation of package 'xts' had non-zero exit status
3: In install.packages("tseries", dependencies = TRUE) :
  installation of package 'TTR' had non-zero exit status
4: In install.packages("tseries", dependencies = TRUE) :
  installation of package 'quantmod' had non-zero exit status
5: In install.packages("tseries", dependencies = TRUE) :
  installation of package 'tseries' had non-zero exit status

然后我尝试使用以下方法安装 quadprog:

install.packages('https://cran.cnr.berkeley.edu/src/contrib/quadprog_1.5-5.tar.gz',dependencies = TRUE,repos = NULL,type ="source")

它给出错误:

/usr/bin/ld: cannot find -lgfortran
collect2: error: ld returned 1 exit status
make: *** [quadprog.so] Error 1
ERROR: compilation failed for package 'quadprog'
* removing '/usr/lib64/R/library/quadprog'

请帮忙看看我该怎么办。我在安装这些软件包时遇到了困难。

我安装了 R 使用:

sudo yum -y 安装 R-core R-devel

我尝试安装 gfortran 使用:yum install gcc-gfortran

它说:软件包 gcc-gfortran-4.4.7-18.el6.x86_64 已经安装并且是最新版本 无事可做

这里的问题是Fortran编译器(gfortran)和GCC编译器驱动(gcc)不同步:gfortran是4.4.7版本,gcc 是版本 4.7.2。这意味着他们使用不同的目录来存储文件,并且 gcc 无法找到 gcc-gfortran 软件包安装的 libgfortran.so 符号 link。

解决方案是将这两个编译器设置为同一版本。这可以通过调整 PATH 变量来实现(根据其他讨论, gcc 这里指的不是 /usr/bin/gcc ),卸载提供此 gcc 命令的软件集合(使用 yum remove devtoolset-1.1-gcc),或使用 yum install devtoolset-1.1-gcc-gfortran.

为同一软件集合安装 Fortran 组件

我最好的猜测是你的 devtoolset-1.1-gcc 包来自这个存储库:

所以您也可以从那里使用 gfortran 包(并选择 c++ 包,以避免类似的问题)。

在同样的错误上花费了相当长的时间后,唯一对我有用的解决方案是重新安装所有 R 组件。

为了完整起见,我所做的是删除所有 R 组件: dpkg -l | grep ^ii | awk ' ~ /^r-/ { print }' | sudo xargs apt-get remove --purge -y(从 here 获取)

然后重新安装 R:sudo apt-get install r-base r-base-dev

我通过使用以下源代码安装 R 来解决此问题:

make install rhome=/usr