更新包索引:
$ sudo apt update
Ubuntu存储库包含稳定的版本R包。但是,如果我们希望安装最新版本的GNU R,请添加官方R-Project 存储库:
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 $ sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu eoan-cran35/'
安装R:
$ sudo apt install r-base
查看安装的r版本
$ R --version
使用r
$ R
Ubuntu存储库包含大约860个可随时安装和使用的稳定库R软件包。
这意味着在大多数情况下,您不需要使用R shell从源代码安装和编译R库。事实上,这一点都不推荐!
您只需使用'apt'命令安装适当的'r-cran'软件包。见下文。
要使用'apt'命令安装其他库,请首先搜索包索引以查找可用的包。例如,让我们看看R库“ggplot2”是否可用:
$ apt-cache search r-cran | grep ggplot2 r-cran-cowplot - GNU R streamlined plot theme and plot annotations for 'ggplot2' r-cran-egg - GNU R extensions for 'ggplot2': custom geom, custom themes, plot r-cran-ggally - GNU R extension to r-cran-ggplot2 r-cran-ggdendro - GNU R create dendrograms and tree diagrams using 'ggplot2' r-cran-ggforce - accelerating GNU R ggplot2 r-cran-ggplot2 - implementation of the Grammar of Graphics r-cran-ggridges - Ridgeline Plots in 'ggplot2' r-cran-ggthemes - extra themes, scales and geoms for r-cran-ggplot2
要安装实际的R库包,执行:
$ sudo apt install r-cran-ggplot2
在R shell加载它来测试是否安装成功:
$ R > library(ggplot2)
日期:2020-07-07 20:55:29 来源:oir作者:oir