R 是一种快速发展的开源编程语言和环境,专门从事统计计算和图形表示。它由 R 统计计算基金会支持,主要供统计学家和数据挖掘人员用于开发统计软件和执行数据分析。
本教程将引导您了解如何在 Debian 9 系统上安装 R。
先决条件#
在继续本教程之前,请确保您已满足以下先决条件:
- Debian 9 系统,至少 1G RAM。如果您的机器内存小于 1GB,您可以创建一个交换文件
.
- 登录身份为具有 sudo 权限的用户
.
在 Debian 上安装 R#
在撰写本文时,R 的最新稳定版本是 3.5 版。 Debian 存储库中的 R 软件包通常已经过时,因此我们将通过添加由以下人员维护的存储库来安装 RCRAN
.
以下步骤描述了如何在 Debian 9 上安装最新稳定版本的 R:
-
安装必要的依赖项添加新存储库通过 HTTPS:
sudo apt install dirmngr apt-transport-https ca-certificates software-properties-common gnupg2
-
通过运行以下命令启用 CRAN 存储库并将 CRAN GPG 密钥添加到您的系统:
sudo apt-key adv --keyserver keys.gnupg.net --recv-key 'E19F5F87128899B192B1A2C2AD5F960A256A04AF'
sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/debian stretch-cran35/'
-
添加存储库后,更新包列表并通过键入以下内容安装 R 包:
sudo apt update
sudo apt install r-base
-
通过运行以下命令来验证安装,该命令将打印 R 版本:
R --version
R version 3.5.1 (2018-07-02) -- "Feather Spray"
Copyright (C) 2018 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
http://www.gnu.org/licenses/.
从 CRAN 安装 R 包#
R 如此受欢迎的主要原因之一是通过综合 R 存档网络 (CRAN) 提供了广泛的软件包。
如果您尚未安装,请安装build-essential
包含编译 R 包所需的工具的包。
sudo apt install build-essential
为了演示目的,我们将安装一个名为stringr,它提供了常见字符串操作的快速、正确的实现。
当以 root 身份启动时,软件包将全局安装并可供所有系统用户使用。如果您在没有 sudo 的情况下启动 R,将为您的用户设置一个个人库。
首先以 root 身份打开 R 控制台:
sudo -i R
R version 3.5.1 (2018-07-02) -- "Feather Spray"
Copyright (C) 2018 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.
>
要安装stringr
包只需输入:
install.packages("stringr")
安装需要一些时间,完成后加载库:
创建一个名为的简单字符向量tutorial
:
tutorial <- c("How", "to", "Install", "R", "on", "Debian", "9")
运行以下函数来打印字符串的长度:
[1] 3 2 7 1 2 6 1
您可以在以下位置找到更多 R 软件包:可用的 CRAN 包(按名称)并安装它们install.packages()
.
结论#
您已成功在 Debian 系统中安装了 R 并了解了如何安装 R 软件包。
如果您遇到问题或有反馈,请在下面发表评论。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)