R 是一种开源编程语言和免费环境,专门从事统计计算和图形表示。它由 R 统计计算基金会支持,主要供统计学家和数据挖掘人员用于开发统计软件和执行数据分析。
本文介绍如何在 CentOS 8 上安装 R。
先决条件#
在继续本教程之前,请确保您已满足以下先决条件:
- 您的系统至少有 1G RAM。否则,创建一个交换文件
.
- 您登录的身份为具有 sudo 权限的用户
.
在 Centos 上安装 R#
R 软件包不包含在 CentOS 8 核心存储库中。我们将从以下位置安装 REPEL 存储库
:
要在 CentOS 8 上安装 R,请按照以下步骤操作:
-
启用EPEL和 PowerTools 存储库:
sudo dnf install epel-release
sudo 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-*
就是这样!您已经成功在 CentOS 系统中安装了 R,并且可以开始使用它了。
从 CRAN 安装 R 包#
R 如此受欢迎的主要原因之一是通过综合 R 存档网络 (CRAN) 提供了大量的软件包。
If the R
二进制文件以 root 或 sudo 身份启动,软件包全局安装并可供所有系统用户使用。要为您的用户设置个人库,请以普通用户身份调用二进制文件。
例如,我们将安装一个名为stringr,它提供了常见字符串操作的快速且正确的实现。
首先以 root 身份打开 R 控制台:
sudo -i 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.
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
选择最接近您所在位置的镜子。
安装将需要一些时间,完成后,通过键入以下内容加载库:
接下来,创建一个名为的简单字符向量tutorial
:
tutorial <- c("How", "to", "Install", "R", "on", "CentOS", "8")
运行以下函数将打印每个字符串的长度:
[1] 3 2 7 1 2 6 1
您可以在以下位置找到更多 R 软件包:克兰包页面,然后安装它们install.packages()
.
结论#
我们向您展示了如何在 CentOS 8 上安装 R 以及如何安装 R 软件包。
如果您遇到问题或有反馈,请在下面发表评论。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)