在Ubuntu 20.04上安装R的最佳方法?

时间:2020-06-26 14:33:40

标签: r ubuntu-20.04

有人在Ubuntu 20.04上安装R是否有好的方法?我似乎无法通过apt找到针对特定于20.04焦点的解决方案。

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:    20.04
Codename:   focal

编辑:通过链接here并将条目添加到sources.list后,我遇到了有关依赖项的问题:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 r-base : Depends: r-base-core (>= 4.0.2-1.2004.0) but it is not going to be installed
          Depends: r-recommended (= 4.0.2-1.2004.0) but it is not going to be installed
          Recommends: r-base-html but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

根据@DirkEddelbuettel的评论,我运行sudo apt install r-base-core r-recommended r-base-html来查看下一级依赖项:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 r-base-core : Depends: libblas3 but it is not installable or
                        libblas.so.3 but it is not installable
               Depends: liblapack3 but it is not installable or
                        liblapack.so.3 but it is not installable
               Depends: libtcl8.6 (>= 8.6.0) but it is not installable
               Depends: libtk8.6 (>= 8.6.0) but it is not installable
               Recommends: r-base-dev but it is not going to be installed
               Recommends: r-doc-html but it is not going to be installed
 r-recommended : Depends: r-cran-kernsmooth (>= 2.2.14) but it is not going to be installed
                 Depends: r-cran-mgcv (>= 1.1.5) but it is not going to be installed
                 Depends: r-cran-rpart (>= 3.1.20) but it is not going to be installed
                 Depends: r-cran-survival (>= 2.13.2-1) but it is not going to be installed
                 Depends: r-cran-matrix but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

当我尝试安装r-base时,还有一个更根本的问题。我最终发现添加PPA后我的未满足依赖项存在问题。我使用此链接here来解决未满足依赖项的潜在问题,这反过来又使我可以进行适当安装,而没有任何安装问题。

2 个答案:

答案 0 :(得分:4)

这是我在Rocker container r-ubuntu for the 20.04 image中所做的事情:

  1. 安装software-properties-common以说add-apt-repository

  2. 为R本身添加rrutter4.0 PPA(与CRAN相同)
    add-apt-repository --enable-source --yes "ppa:marutter/rrutter4.0"

  3. 为超过4k个CRAN软件包添加c4d4u.teams存储库:
    add-apt-repository --enable-source --yes "ppa:c2d4u.team/c2d4u4.0+"

  4. 运行apt install r-base(还有更多)。

从狭义上讲,您只需要2个(因为在完整的Ubuntu系统上可能不需要1个)和4个,但是您也可能需要3个。

您当然也可以只docker pull rocker/r-ubuntu:20.04并预制该容器,但是我同时使用了:一个用于测试的容器以及这些设置在我的20.04机器上。

答案 1 :(得分:0)

先决条件

您将需要一个 Ubuntu 20.04:

至少 1GB 内存 具有 sudo 权限的 root 用户/非 root 用户

安装 R

因为 R 是一个快速发展的项目,最新的稳定版本并不总是可以从 Ubuntu 的存储库中获得,所以我们将首先添加由 CRAN 维护的外部存储库。

注意:CRAN 在其网络内维护存储库,但并非所有外部存储库都是可靠的。请务必仅从受信任的来源安装。

我们先添加相关的 GPG 密钥。

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9

请注意,如果您不使用 20.04,您可以从 R Project Ubuntu 列表中找到相关存储库,以每个版本命名。 Ubuntu 20.04 被称为 Focal Fossa,而 R 的最新版本是 4.0.0,因此下面的存储库的命名约定是——focal-cran40。

sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'

现在,我们需要在此之后运行更新以包含来自新存储库的包清单。

sudo apt update

此时,我们已准备好使用以下命令安装 R。

sudo apt install r-base

如果提示确认安装,请按 y 继续。

终于进入R shell-

sudo -i R

这确认我们已成功安装 R 并进入其交互式 shell。