linux系统中安装R包

1、查看R版本

[root@centos8 test]# R --version
R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
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 the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.

2、启动R

[root@centos8 test]# R

R version 4.0.3 (2020-10-10) -- "Bunny-Wunnies Freak Out"
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.

  Natural language support but running in an English locale

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.

>

3, 测试data.table包

> library(data.table)
Error in library(data.table) : there is no package called ‘data.table’

4、安装data.table包

镜像列表:https://cran.r-project.org/mirrors.html

> install.packages('data.table', repos='https://mirror.lzu.edu.cn/CRAN/')
…………
…………
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (data.table)

The downloaded source packages are in/tmp/Rtmpaq8Ble/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done

5、测试data.dable包

> library(data.table)
data.table 1.13.6 using 1 threads (see ?getDTthreads).  Latest news: r-datatable.com
> dir()
[1] "result.map"
> test <- fread("result.map")
> class(test)
[1] "data.table" "data.frame"
> dim(test)
[1] 533453      4
> head(test)
   V1              V2        V3    V4
1:  1 oar3_OAR1_17218 0.0203308 17218
2:  1 oar3_OAR1_20658 0.0243928 20658
3:  1 oar3_OAR1_28296 0.0334116 28296
4:  1 oar3_OAR1_31152 0.0367840 31152
5:  1 oar3_OAR1_38175 0.0450767 38175
6:  1 oar3_OAR1_38264 0.0451817 38264

可以调用。

6、测试ggplot2包

> library(ggplot2)
Error in library(ggplot2) : there is no package called ‘ggplot2’

7、安装ggplot2包

> install.packages('ggplot2', repos='https://mirror.lzu.edu.cn/CRAN/')
…………
…………
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (ggplot2)

The downloaded source packages are in/tmp/Rtmpaq8Ble/downloaded_packages’
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done

8、测试ggplot2包

> library(ggplot2)
> ggplot(mtcars,aes(x=wt,y=mpg)) + geom_point()
> dir()
[1] "result.map" "Rplots.pdf"
> ggsave('1.pdf',dpi = 1080)
Saving 7 x 7 in image
> dir()
[1] "1.pdf"      "result.map" "Rplots.pdf"

可以调用。

原文地址:https://www.cnblogs.com/liujiaxin2018/p/14359937.html