Configuration of R language (3.6.3) in ubuntu20.04 environment


Preface

Recently, the author used R language for data analysis and visualization in an experimental assignment, and encountered some errors during the configuration process, so I will record it here.

Note: The following processes are all run in docker containers , so there is no sudo prefix. If the reader configures R locally, please execute the instructions in the article in root mode, or add the sudo prefix before each instruction to ensure that the instructions can be executed smoothly.


1. Mirror source configuration

Here I used the Alibaba image source, and the /etc/apt/source.list file configuration is as follows:

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

2. Installation steps

1. Environment installation:

First update the software source list

apt-get update
Hit:1 http://mirrors.aliyun.com/ubuntu focal InRelease
Get:2 http://mirrors.aliyun.com/ubuntu focal-security InRelease [114 kB]
Get:3 http://mirrors.aliyun.com/ubuntu focal-updates InRelease [114 kB]
Get:4 http://mirrors.aliyun.com/ubuntu focal-proposed InRelease [267 kB]
Get:5 http://mirrors.aliyun.com/ubuntu focal-backports InRelease [101 kB]
Get:6 http://mirrors.aliyun.com/ubuntu focal-updates/main Sources [561 kB]
Get:7 http://mirrors.aliyun.com/ubuntu focal-updates/restricted Sources [34.6 kB]
Get:8 http://mirrors.aliyun.com/ubuntu focal-updates/restricted amd64 Packages [738 kB]
Get:9 http://mirrors.aliyun.com/ubuntu focal-updates/main amd64 Packages [1689 kB]
Fetched 3618 kB in 3s (1198 kB/s)                        
Reading package lists... Done

If the above feedback appears, the update is successful. Next, install the R language environment.

apt-get install r-base

During the execution process, the installation package may not be located or the installation may fail. In this case, you can execute the first step command apt-get update again to update it to solve the problem.
The entire downloading process takes a long time and is also limited by network speed, so please be patient.
When the following statement to set a trigger appears:

Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...

That means the installation is successful. Next, enter the command R to start R and enter the > command prompt state:

root@2b61055a74c7:/# 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.

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.

> 

At this point, the simple R language environment has been successfully installed. Enter q() to exit this state. Enter n to save the environment. Next, set the dependent library mirror source of the R language.

2. Dependency library mirror source settings

When using R language for data analysis, like other languages, you need to use many external dependency packages, such as ggplot, RMySQL, etc. When installing these dependency libraries, you also need to set the corresponding mirror address to increase the download speed.

First find the default download address configuration file /etc/R/Rprofile.site
Rprofile.site (original configuration) of the R dependent library:

local({
    
    
    r <- getOption("repos")
    r["CRAN"] <- "https://cloud.r-project.org"
    options(repos = r)
})

We need to modify the URL in CRAN to the mirror website we specify. Here we take the Alibaba mirror source as an example:
Rprofile.site (modified configuration):

local({
    
    
    r <- getOption("repos")
    r["CRAN"] <- "https://mirrors.aliyun.com/CRAN/"
    options(repos = r)
})

This solves the problem of slow download of dependent libraries.

In addition, it should be noted that when setting the mirror source of R, the mirror source of the same company must be used. It is not allowed to install R with Ali mirror, but use Tsinghua source for the dependent library. In this way, serious component version dependency problems will occur when installing external dependent libraries. , causing R to fail to run properly.


Summarize

The above is the entire process of installing the R language environment under ubuntu20.04. Thank you for reading.

Guess you like

Origin blog.csdn.net/weixin_45704680/article/details/121478366