如何在CentOS 8上安装R
时间:2020-03-05 15:31:31 来源:igfitidea点击:
R是一种开源编程语言和免费环境,专门从事统计计算和图形表示。
它受到R统计计算基金会的支持,主要由统计学家和数据挖掘人员用于开发统计软件和执行数据分析。
本文介绍了如何在CentOS 8上安装R。
准备工作
在继续本教程之前,请确保满足以下准备工作:
- 系统至少有1G的内存。否则,请创建一个交换文件。
- 我们以具有sudo特权的用户身份登录。
在Centos上安装R
R软件包不包含在CentOS 8核心存储库中。
我们将从EPEL存储库中安装R:
要在CentOS 8上安装R,请执行以下步骤:
- 启用EPEL和PowerTools存储库:
sudo dnf install epel-releasesudo dnf config-manager --set-enabled PowerTools
- 通过键入以下命令安装R:
sudo yum install R
R是包含所有必需的R组件的元包。
- 通过打印R版本来验证安装:
R --version
在撰写本文时,R的最新稳定版本是3.6.2版:
R version 3.6.2 (2019-12-12) -- "Dark and Stormy Night" Copyright (C) 2019 The R Foundation for Statistical Computing Platform: x86_64-redhat-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/.
- 安装常见的R软件包所使用的库和工具:
sudo yum install make gcc gcc-c++ libcurl-devel libxml2-devel openssl-devel texlive-*
就是这样!我们已经成功安装了RCentOS系统,并且可以开始使用它了。
从CRAN安装R软件包
R之所以如此受欢迎的主要原因之一是可以通过综合R存档网络(CRAN)获得大量的软件包。
如果以root或者sudo身份启动“ R”二进制文件,则软件包将全局安装并可供所有系统用户使用。
要为用户设置个人库,请以普通用户身份调用二进制文件。
作为示例,我们将安装一个名为'stringr'的软件包,该软件包可快速,正确地实现常见的字符串操作。
首先以根用户身份打开R控制台:
sudo -i R
R version 3.6.3 (2017-02-29) -- "Holding the Windsock" Copyright (C) 2017 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. >
以下命令在R控制台中执行。
安装'stringr'软件包:
install.packages("stringr")
系统将要求我们选择一个CRAN镜像:
Installing package into ‘/usr/lib64/R/library’ (as ‘lib’ is unspecified) --- Please select a CRAN mirror for use in this session -- Secure CRAN mirrors
选择离我们最近的镜子。
安装将花费一些时间,一旦完成,请通过键入以下内容加载库:
library(stringr)
接下来,创建一个名为'tutorial'的简单字符向量:
tutorial <- c("How", "to", "Install", "R", "on", "CentOS", "8")
运行以下函数,该函数将打印每个字符串的长度:
str_length(tutorial)
[1] 3 2 7 1 2 6 1
我们可以在CRAN软件包页面中找到更多R软件包,并使用'install.packages()'安装它们。