安装R语言(Rstudio、R、RTools)

安装R语言(Rstudio、R、RTools)

本文介绍一下从零搭建R环境。

那么R语言,RTools和Rstudio有什么区别?

R是基本的编程语言,单纯使用R是可以的,如图:

image-20221207112951762
image-20221207112951762

为了编写R程序,单独的R语言肯定不够,因为需要对数据、文档、函数的批量管理,这个时候需要Rstudio。(我这里是VScode)

image-20221207121355279
image-20221207121355279

这个时候,我们可以查看变量、绘图、管理项目。可能有些东西不满足,比如下载GitHub的包等等,这个时候,你就要安装Rtool。

R语言安装

首先安装R,点击Windows

https://cran.r-project.org/index.html

推荐选择镜像:

https://mirrors.tuna.tsinghua.edu.cn/CRAN/

image-20230413111355178
image-20230413111355178

再点击base:

image-20230413111428620
image-20230413111428620

点击Download R-4.2.3 for Windows,下载最新版4.2.3。

或点击Previous,下载一个之前的稳定版本,如4.1.2

image-20230413111500452
image-20230413111500452

下载完安装包一路点到底,安装即可。

Rstudio

https://posit.co/products/open-source/rstudio/

点击右上角的Download,再点击Download Rstudio

image-20230413111947756
image-20230413111947756

之前我们已经安装好R了,因此直接下载Rstudio安装

image-20230413112058556
image-20230413112058556

下载好双击exe运行到底就行了。

Rtools

Rtools安装包有130M,且安装文件有1G,正常安装包括镜像安装都会很慢,这时候需要使用一些工具:

NDM下载器:https://www.neatdownloadmanager.com/index.php/en/

Rtools下载地址:https://cran.r-project.org/bin/windows/Rtools/

我选择的是最新版Rtools40,64位32位兼容版本,这个可以根据自己情况合理选择

image-20221207131803572
image-20221207131803572

将下面的Rtools下载地址复制到NDM的url栏里,即可下载

https://cran.r-project.org/bin/windows/Rtools/rtools40-x86_64.exe

image-20221207131838137
image-20221207131838137

下载好了直接安装rtool,双击即可

安装好了打开R

image-20221207131915099
image-20221207131915099

输入:

writeLines('PATH="${RTOOLS40_HOME}\usr\bin;${PATH}"', con = "~/.Renviron")
  • 1

再输入:

Sys.which("make")
  • 1

若输出R路径则成功

image-20221207132019924
image-20221207132019924

本文由 mdnice 多平台发布