在 RStudio 中从源代码安装 R 包时出现问题 - Ubuntu 16.04

Problems installing R packages from source in RStudio - Ubuntu 16.04

我是 运行 Ubuntu 16.04 64 位上的 R 和 RStudio,我正在尝试进行聚类分析,但我认为我的错误并非特定于此包...但是当我尝试从 CRAN 安装包“ClusterR”时,出现以下错误。

> install.packages("ClusterR")
Installing package into ‘/home/daniel/R/x86_64-pc-linux-gnu-library/3.4’
(as ‘lib’ is unspecified)
also installing the dependencies ‘tiff’, ‘OpenImageR’, ‘gmp’

trying URL 'https://cran.rstudio.com/src/contrib/tiff_0.1-5.tar.gz'
Content type 'application/x-gzip' length 28925 bytes (28 KB)
==================================================
downloaded 28 KB

trying URL 'https://cran.rstudio.com/src/contrib/OpenImageR_1.0.6.tar.gz'
Content type 'application/x-gzip' length 802641 bytes (783 KB)
==================================================
downloaded 783 KB

trying URL 'https://cran.rstudio.com/src/contrib/gmp_0.5-13.1.tar.gz'
Content type 'application/x-gzip' length 131321 bytes (128 KB)
==================================================
downloaded 128 KB

trying URL 'https://cran.rstudio.com/src/contrib/ClusterR_1.0.5.tar.gz'
Content type 'application/x-gzip' length 916490 bytes (895 KB)
==================================================
downloaded 895 KB

* installing *source* package ‘tiff’ ...
** package ‘tiff’ successfully unpacked and MD5 sums checked
** libs
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG      -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c common.c -o common.o
In file included from common.c:1:0:
common.h:5:18: fatal error: tiff.h: No such file or directory
compilation terminated.
/usr/lib/R/etc/Makeconf:159: recipe for target 'common.o' failed
make: *** [common.o] Error 1
ERROR: compilation failed for package ‘tiff’
* removing ‘/home/daniel/R/x86_64-pc-linux-gnu-library/3.4/tiff’
Warning in install.packages :
  installation of package ‘tiff’ had non-zero exit status
* installing *source* package ‘gmp’ ...
** package ‘gmp’ successfully unpacked and MD5 sums checked
creating cache ./config.cache
checking for __gmpz_ui_sub in -lgmp... no
configure: error: GNU MP not found, or not 4.1.4 or up, see http://gmplib.org
ERROR: configuration failed for package ‘gmp’
* removing ‘/home/daniel/R/x86_64-pc-linux-gnu-library/3.4/gmp’
Warning in install.packages :
  installation of package ‘gmp’ had non-zero exit status
ERROR: dependency ‘tiff’ is not available for package ‘OpenImageR’
* removing ‘/home/daniel/R/x86_64-pc-linux-gnu-library/3.4/OpenImageR’
Warning in install.packages :
  installation of package ‘OpenImageR’ had non-zero exit status
ERROR: dependencies ‘OpenImageR’, ‘gmp’ are not available for package ‘ClusterR’
* removing ‘/home/daniel/R/x86_64-pc-linux-gnu-library/3.4/ClusterR’
Warning in install.packages :
  installation of package ‘ClusterR’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/RtmpuIo1WM/downloaded_packages’

事实上,如果我尝试只安装包“tiff”,我会得到同样的错误,在此处提炼:

Installing package into ‘/home/daniel/R/x86_64-pc-linux-gnu-library/3.4’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/src/contrib/tiff_0.1-5.tar.gz'
Content type 'application/x-gzip' length 28925 bytes (28 KB)
==================================================
downloaded 28 KB

* installing *source* package ‘tiff’ ...
** package ‘tiff’ successfully unpacked and MD5 sums checked
** libs
gcc -std=gnu99 -I/usr/share/R/include -DNDEBUG      -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c common.c -o common.o
In file included from common.c:1:0:
common.h:5:18: fatal error: tiff.h: No such file or directory
compilation terminated.
/usr/lib/R/etc/Makeconf:159: recipe for target 'common.o' failed
make: *** [common.o] Error 1
ERROR: compilation failed for package ‘tiff’
* removing ‘/home/daniel/R/x86_64-pc-linux-gnu-library/3.4/tiff’
Warning in install.packages :
  installation of package ‘tiff’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/RtmpuIo1WM/downloaded_packages’

我对 R 和 Ubuntu 仍然是一个编码新手,所以我不确定我在这里遗漏了什么?我有一种感觉,我在 Ubuntu 中缺少一些 dependency/library,这是在 R 中以这种方式从源代码安装所必需的,但我不确定是什么?而且我从源代码安装其他包时没有遇到任何问题,甚至包括加载了'ClusterR'的其他包。

我安装了 GCC Fortran,这里列出了终端代码:

daniel@fulgur-desktop:~$ gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

R 包通常具有通常无法通过 R 安装的外部系统依赖项。如果您检查 CRAN package docs for the tiff package it mentions tiff and jpeg libraries are required. Anyway, looking around on Ubuntu package list and making a search for tiff 导致 libtiff5-dev 包。 运行

sudo apt-get install libtiff5-dev

你应该没事的。请注意,为了安装 R 包的系统要求,您通常希望安装最后带有 -dev 的版本。

对于mac,你可以使用brew:

brew install -v libtiff

然后在R中安装包镜像时出现如下错误:

configure: error: X11 not found but required, configure aborted.

为 mac 安装 X11 已解决:https://www.xquartz.org/index.html