在 Ubuntu 18.04 上安装 R 3.6 的 ggplot2

在 Ubuntu 18.04 上安装 R 3.6 的 ggplot2

我已经安装了 R 3.6r-project.org 存储库,按照说明这篇文章来自 R Bloggers。现在我想安装该ggplot2软件包,但没有成功。

通常我更喜欢将所有内容都安装为用户包,这样 R 效果会更好。但是,对于此版本isoband,依赖的包ggplot2无法编译:

$ sudo R 

R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> install.packages("ggplot2")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
also installing the dependency ‘isoband’

trying URL 'https://cloud.r-project.org/src/contrib/isoband_0.2.0.tar.gz'
Content type 'application/x-gzip' length 1894070 bytes (1.8 MB)
==================================================
downloaded 1.8 MB

trying URL 'https://cloud.r-project.org/src/contrib/ggplot2_3.3.0.tar.gz'
Content type 'application/x-gzip' length 3031461 bytes (2.9 MB)
==================================================
downloaded 2.9 MB

* installing *source* package ‘isoband’ ...
** package ‘isoband’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG  -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/testthat/include"   -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c RcppExports.cpp -o RcppExports.o
In file included from /usr/local/lib/R/site-library/Rcpp/include/Rcpp.h:79:0,
                 from RcppExports.cpp:4:
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/Rmath.h: In function ‘double R::pythag(double, double)’:
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/Rmath.h:222:57: error: ‘::Rf_pythag’ has not been declared
     inline double pythag(double a, double b) { return ::Rf_pythag(a, b); }
                                                         ^~~~~~~~~
/usr/local/lib/R/site-library/Rcpp/include/Rcpp/Rmath.h:222:57: note: suggested alternative: ‘pythag’
     inline double pythag(double a, double b) { return ::Rf_pythag(a, b); }
                                                         ^~~~~~~~~
                                                         pythag
/usr/lib/R/etc/Makeconf:177: recipe for target 'RcppExports.o' failed
make: *** [RcppExports.o] Error 1
ERROR: compilation failed for package ‘isoband’
* removing ‘/usr/local/lib/R/site-library/isoband’
ERROR: dependency ‘isoband’ is not available for package ‘ggplot2’
* removing ‘/usr/local/lib/R/site-library/ggplot2’

The downloaded source packages are in
    ‘/tmp/RtmpzfegOo/downloaded_packages’
Warning messages:
1: In install.packages("ggplot2") :
  installation of package ‘isoband’ had non-zero exit status
2: In install.packages("ggplot2") :
  installation of package ‘ggplot2’ had non-zero exit status
> 

相同R 博主帖子建议使用 Michael Rutter 的 PPA 作为预编译软件包的来源。但是,这个 PPA 似乎正在安装不兼容版本的软件包:

$ sudo add-apt-repository ppa:marutter/c2d4u3.5
[...]

$ sudo apt-get update
[...]

$ R

R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library("ggplot2")
Error: package or namespace load failed for ‘ggplot2’:
 package ‘scales’ was installed by an R version with different internals; it needs to be reinstalled for use with this R version
> 

ggplot2在 Ubuntu 18.04 上安装 R 3.6 是否有不同的方法?

答案1

在安装 R 3.6 之前,我按照R 博主帖子

sudo apt purge r-base r-recommended r-cran-*
sudo apt autoremove
sudo apt update

但这还不够。它留下了一个文件夹,里面有本地编译的 R 包。这可能是包的一个错误r-base,即使apt purge留下了资产:

$ ls /usr/local/lib/R/site-library
assertthat  desc      ggplot2    lifecycle     pkgload      purrr         rprojroot   tidyselect
backports   digest    glue       lubridate     plogr        R6            rstudioapi  timeDate
BH          dplyr     gower      magrittr      plyr         ranger        scales      utf8
callr       ellipsis  gtable     ModelMetrics  praise       RColorBrewer  SQUAREM     vctrs
caret       evaluate  ipred      munsell       prettyunits  Rcpp          stringi     viridisLite
cli         fansi     isoband    numDeriv      pROC         RcppEigen     stringr     withr
colorspace  farver    iterators  pillar        processx     recipes       testthat
crayon      foreach   labeling   pkgbuild      prodlim      reshape2      tibble
data.table  generics  lava       pkgconfig     ps           rlang         tidyr

因此,要彻底删除旧版 R,必须删除此文件夹:

sudo rm -Rf /usr/local/lib/R/site-library

是的,可以从 r-project.org 安装更新的版本:

sudo apt install r-base r-base-core r-recommended

这样就可以使用如下方法安装ggplot2install.packages

R
[...]
> install.packages("ggplot2")

相关内容