A.14 安装 R 包

Iñaki Ucar 开发的 cran2copr 项目实现在 Fedora 上安装预编译好的二进制 R 包,项目目的类似 Debian 平台上的 cran2deb

  1. devtools 是开发 R 包的常用工具,同时具有很重的依赖,请看

    tools::package_dependencies('devtools', recursive = TRUE)
    ## $devtools
    ##   [1] "usethis"     "cli"         "desc"        "ellipsis"    "fs"         
    ##   [6] "lifecycle"   "memoise"     "miniUI"      "pkgbuild"    "pkgdown"    
    ##  [11] "pkgload"     "profvis"     "rcmdcheck"   "remotes"     "rlang"      
    ##  [16] "roxygen2"    "rversions"   "sessioninfo" "stats"       "testthat"   
    ##  [21] "tools"       "urlchecker"  "utils"       "withr"       "R6"         
    ##  [26] "rprojroot"   "methods"     "glue"        "cachem"      "shiny"      
    ##  [31] "htmltools"   "callr"       "crayon"      "prettyunits" "processx"   
    ##  [36] "bslib"       "digest"      "downlit"     "httr"        "jsonlite"   
    ##  [41] "magrittr"    "purrr"       "ragg"        "rmarkdown"   "tibble"     
    ##  [46] "whisker"     "xml2"        "yaml"        "htmlwidgets" "stringr"    
    ##  [51] "vctrs"       "curl"        "xopen"       "brew"        "commonmark" 
    ##  [56] "knitr"       "stringi"     "cpp11"       "brio"        "evaluate"   
    ##  [61] "praise"      "ps"          "waldo"       "clipr"       "gert"       
    ##  [66] "gh"          "rappdirs"    "rstudioapi"  "graphics"    "grDevices"  
    ##  [71] "sass"        "jquerylib"   "base64enc"   "mime"        "fastmap"    
    ##  [76] "fansi"       "askpass"     "credentials" "openssl"     "sys"        
    ##  [81] "zip"         "gitcreds"    "httr2"       "ini"         "highr"      
    ##  [86] "xfun"        "systemfonts" "textshaping" "fontawesome" "tinytex"    
    ##  [91] "httpuv"      "xtable"      "sourcetools" "later"       "promises"   
    ##  [96] "pillar"      "pkgconfig"   "diffobj"     "rematch2"    "Rcpp"       
    ## [101] "utf8"

    其中,依赖关系见表 A.2

    表 A.2: devtools 的系统依赖
    curl git2r openssl
    Ubuntu libcurl-dev49 libgit2-dev libssl-dev
    CentOS libcurl-devel libgit2-devel openssl-devel
  1. sf 是处理空间数据的常用工具

    tools::package_dependencies('sf', recursive = TRUE)
    ## $sf
    ##  [1] "methods"    "classInt"   "DBI"        "graphics"   "grDevices" 
    ##  [6] "grid"       "magrittr"   "Rcpp"       "s2"         "stats"     
    ## [11] "tools"      "units"      "utils"      "e1071"      "class"     
    ## [16] "KernSmooth" "wk"         "MASS"       "proxy"

    其主要的系统依赖分别是 GEOS 3.5.1, GDAL 2.2.2, PROJ 4.9.2

    sudo add-apt-repository -y ppa:ubuntugis/ubuntugis-unstable
    sudo apt-get update
    sudo apt-get install -y libudunits2-dev libgdal-dev libgeos-dev libproj-dev 

    这样也同时解决了 udunits2rgdalrgeos 等 3个 R 包的系统依赖,其中 udunits2 使用如下命令安装

    install.packages(’udunits2’, configure.args = '--with-udunits2-include=/usr/include/udunits2')
  2. 图形设备支持 cairo png jpeg tiff

    sudo apt-get install -y libcairo2-dev libjpeg-dev libpng-dev libtiff-dev 
  3. 图像处理 imagermagick

    sudo yum install fftw-devel # CentOS
    sudo apt-get install libfftw3-dev # Ubuntu

    在 Ubuntu 系统上安装最新的 libmagick++-dev 库

    sudo add-apt-repository -y ppa:opencpu/imagemagick
    sudo apt-get update
    sudo apt-get install -y libmagick++-dev 

    在 CentOS 系统上

    sudo yum install -y ImageMagick-c++-devel

    然后安装 R 包 install.packages(c('imager', 'magick'))

  4. rgl 是绘制真三维图形的重量级 R 包

    sudo apt-get install libcgal-dev libglu1-mesa-dev libx11-dev # Ubuntu
    sudo yum install mesa-libGLU mesa-libGLU-devel # CentOS

    然后安装 R 包

    install.packages('rgl')

    在 Ubuntu 系统上还可以这样安装

    sudo add-apt-repository ppa:marutter/rrutter3.5
    sudo apt-get update
    sudo apt-get install r-cran-rgl
  5. rJava 是 Java 语言和 R 语言之间实现通信交流的桥梁

    sudo apt-get install -y default-jdk
    sudo R CMD javareconf

    然后安装 rJava 包 install.packages(’rJava’)

  6. igraph 是网络数据分析的必备 R 包,为了发挥其最大性能,需要安装三个系统依赖

    sudo apt-get install -y libgmp-dev libxml2-dev libglpk-dev

    然后安装 R 包

    install.packages('igraph')
  7. gpuR 是基于 GPU 进行矩阵计算的扩展包,依赖 RcppEigen 确保安装 OpenCL 和 RViennaCL 或者 安装 Nvidia 驱动和 CUDA,使用 gpuRcudagputools 扩展包,下面安装指导来自其 Wiki

    # Install OpenCL headers
    sudo apt-get install opencl-headers opencv-dev
    
    # Install NVIDIA Drivers and CUDA
    sudo add-apt-repository -y ppa:xorg-edgers/ppa
    sudo apt-get update
    sudo apt-get install nvidia-346 nvidia-settings
  8. nloptrNLopt 的 R 语言接口,首先安装 NLopt 程序库 sudo apt-get install libnlopt-dev 然后安装 R 包install.packages('nloptr'),nloptr 被 700+ R 包依赖,如 lme4spaMMglmmTMBrstanarm 等。

  9. Rmpfr

    sudo apt-get install libmpfr-dev
    install.packages(’Rmpfr’)
  10. geojson

    sudo yum install jq-devel protobuf-devel
    install.packages(c('geojson','geojsonio','jqr','protolite'))
  11. lgcp

    sudo yum install bwidget
    install.packages(c('rpanel','lgcp'))
  12. ijtiff

    sudo yum install jbigkit-devel
    install.packages('ijtiff')
  13. webshot 包用于截图

    sudo apt install phantomjs
    install.packages(’webshot’)
  14. gifski 包合成 GIF 动图

    sudo apt-get install cargo
    install.packages('gifski')

  1. libcurl-dev 是一个虚包 virtual package,由 libcurl4-openssl-dev 或 libcurl4-nss-dev 或 libcurl4-gnutls-dev 实际提供,选择其中一个安装即可。↩︎