Installation of R language (detailed tutorial)


foreword

I don’t produce knowledge, I’m just a porter of knowledge. The following content is from Bilibili - Xuzhou Geng’s installation tutorial: probably the best R language installation guide 哔哩哔哩bilibili

Personally, I think the installation of R is more troublesome, so I modified the installation video he talked about and wrote it in the form of a document, so that I or others can refer to it in the future


1. What is the R language?

The R language is a language and operating environment for statistical analysis and graphics. R is a free, free, open-source software belonging to the GNU system. It is an excellent tool for statistical computing and statistical graphics.

insert image description here

2. R download

1. Official website

Official website: https://www.r-project.org/

Enter the official website, which is like this

insert image description here
R is a free software environment for statistical computing and graphics. It compiles and runs on a wide variety of UNIX platforms, Windows and MacOS. To download R, please choose your preferred CRAN mirror.

clickdownload R

insert image description here

You will enter this page, you can see a lot of mirror images

insert image description here

If you are in China, choose the Chinese mirror, so that the download will be faster

you can just choose the first oneTsinghua University Open Sourcemirror image of

insert image description here
What is a mirror, and why choose a Chinese mirror?

Mirroring is a form of file storage and a type of redundancy. The data on one disk has an identical copy on another disk, which is a mirror.

This is the explanation on Baidu, and it seems rather difficult to understand. To put it simply, it is: for example, there is a cheese factory in the United States, and then a cheese factory is also built in China. The cheese produced in these two countries is the same, so it can be considered These two cheese factories are mirror images of each other. If you want to eat cheese, will you go to the United States to buy cheese or go to China to buy cheese? That must be China, because it is close, and it is fast, which is why we choose the mirror image of China.

After selecting the mirror image and entering it, it looks like this. You can see that there are download and installation packages for three operating systems here.

insert image description here

You are using the system on which to download the installation package corresponding to that system

I am here to use it under windows, so I choose Download for Windows(it is recommended to use R under windows)

insert image description here
Click to see this page, and then click baseand Rtoolsto jump into R's 基本and 工具download pages respectively

insert image description here

2. download base

Click baseto enter like this

insert image description here

If you want to download the latest version of R, you can directly click the download address at the top

insert image description here
To download historical versions of R, click here Previous releasesto select the version you want

insert image description here

For example, I choose the first version of R 4.1.2 and click to enter

insert image description here
select this .exedownload

insert image description here
save document

insert image description here

3. download Rtools

Click Rtoolsto enter like this

insert image description here

Click Older editionsto view all versions

insert image description here

The Rtools version you want to download should be the same as the base version you downloaded earlier

For example, the version I downloaded from base before is4.1.2, then Rtools should choosertools40-x86_64.exeto download

then save

insert image description here
The download of R and RTools is complete


3. Rstudio download

1. Official website

Official website: https://www.rstudio.com

insert image description here

2. download Rstudio

You can click DOWNLOAD FREE DESKTOP IDEto enter the download page

insert image description here

chooseRStudio Desktop - FreeunderDOWNLOAD

insert image description here
Jump here, click 下载, both places are fine

insert image description here

保存

insert image description here

I created a new folder on the D drive to save the three executable files I downloaded before.

insert image description here

Below I also provide three executable files related to R installation that I downloaded.
百度网盘下载链接
Link: Network disk link
Extraction code: ikya

Subsequent installations are basically fool-proof installations


Four, R installation

Double-click the previously downloaded executable fileR-X.X.X-xxx.exe

insert image description here

Select the language used for installation,确定

insert image description here

下一步

insert image description here
Choose a non-Chinese installation path, it is not recommended to have spaces in the path (if you install it in a Chinese path, there may be problems), I will download it directly to the C drive, because my C drive is quite large now,下一步

insert image description here

Remove unnecessary things (my computer is 64-bit, and then I don't need translation),下一步

insert image description here

accept default options下一步

insert image description here
下一步

insert image description here

下一步

insert image description here

Start the download
insert image description here
and the installation is complete, click结束

insert image description here


Five, Rtools installation

Double-click the previously downloaded executable fileRtools-XXXXX.exe

insert image description here
next

insert image description here
clicknext

insert image description here
clickInstall

insert image description here
start download…

insert image description here
The installation is complete, clickFinish

insert image description here


6. Rstudio installation

Double-click the previously downloaded executable fileRStudio-XXXXX.exe

insert image description here
click下一步

insert image description here
The same installation directory should not be under the Chinese path

insert image description here

click安装

insert image description here
installing…

insert image description here
The installation is complete, click完成

insert image description here


Seven, java environment configuration

Why configure java environment variables?

Some packages in R depend on java, and some commands cannot be used without configuration

You can view this link for configuration: java environment configuration (detailed tutorial)


8. Run RStudio

insert image description here
If it can be opened, it means that the R language and RStudio are installed successfully.

In Toolsthe Global Optionscan set some global properties, such as font, size, etc...

You can simply try to draw a picture

plot(x=1,y=1)

insert image description here


10. R package installation strategy

1. Configure mirroring

1. Modify the configuration file

Find the file that Rprofile.siteconfigures (I installed it by default, and you can usually find the configuration file under the Program Files folder of the C drive), open it in Notepad, and paste the following configuration
insert image description here

## 设置镜像
local({
    
    r <- getOption("repos")
     r["CRAN"] <- "https://mirrors.tuna.tsinghua.edu.cn/CRAN/"
     options(repos=r)}
     )
options(BioC_mirror="https://mirrors.ustc.edu.cn/bioc/")

## 设置下载方式
options("download.file.method"="libcurl")
options("url.method"="libcurl")

insert image description here
If you can't save it when you save it, you may wish to copy this file to your desktop first, and replace the file in the etc directory after you modify it on your desktop.

insert image description here

Check whether the mirroring is configured successfully

input the command

getOption("repos")

getOption("BioC_mirror")

insert image description here
Appearing this means that the mirror configuration is successful

1. Modify global settings

at ToolstheGlobal Options

insert image description here

Choose a mirror image of China

insert image description here

2. Simple commands

命令 + enter ==> 执行

See where R packages are installed

.libPaths()

insert image description here
View installed R packages

installed.packages()

insert image description here
View installable R packages

available.packages()

insert image description here

Check if a package exists

library(包名)

例如:library(xlsx)

Install local R packages

install.packages("输入你文件的地址",repos = NULL)

例如:
install.packages("~/../Desktop/GO.db_3.7.0.tar.gz",repos = NULL)

View documentation

?install.packages

insert image description here
Uninstall the R package

remove.packages("R包名")

例如:
remove.packages("xlsx")

3. Upgrade the R package

The following are the packages that are often used, copy the following command and press Enter to execute it.

update.packages()

if(!require("xlsx")) install.packages("xlsx")
if(!require("tidyr")) install.packages("tidyr")
if(!require("dplyr")) install.packages("dplyr")
if(!require("ggplot2")) install.packages("ggplot2")
if(!require("data.table")) install.packages("data.table")
if(!require("ggrepel")) install.packages("ggrepel")
if(!require("devtools")) install.packages("devtools")
if(!require("BiocManager")) install.packages("BiocManager")

insert image description here
It may take some time,
insert image description here
the downloaded package will go to this directory

insert image description here

4. Install the R package on Bioconductor

Copy the following command and press Enter to execute it

BiocManager::install()

if(!require("DESeq2")) BiocManager::install("DESeq2")
if(!require("clusterProfiler")) BiocManager::install("clusterProfiler")

insert image description here

Summarize

Thanks to the big guy for sharing, I was able to install R on my computer with difficulty, and make a record of this. In case I need to download R in the future, I don’t need to spend time watching the video. I will also share some notes on my learning R language in the future. .

Guess you like

Origin blog.csdn.net/xhmico/article/details/122443660