- 下载源码包
- 在http://cran.r-project.org/mirrors.html,选择一个国内镜像下载需要的版本,比如:http://mirror.lzu.edu.cn/CRAN/src/base/R-3/,这儿我下载了R-3.1.3版的源码,大约20多M,很快就下载完成。
- 解压源码
- 压缩包我放在/user/local目录下,进入此目录后运行命令:
- tar xzf R-3.1.3.tar.gz
- 解压到当前目录
- 检查编译环境及编译
- 进入目录
- cd R-3.1.3
- ./configure
-
checking for g++... no checking for c++... no
configure: error: No F77 compiler found...会有一大堆不满足的条件 -
安装对应的依赖即可
yum install gcc-c++ (如果没有安装c和c++的编译器)
yum install readline-devel
yum install libXt-devel
yum install gcc-gfortran (解决configure: error: No F77 compiler found 错误)
- ./configure --enable-R-shlib --prefix=/usr/R-3.1.3
make
make install
- 将/usr/local/R-3.1.3/bin加入用户或系统环境变量的path里边:
比如:vim /etc/profile
增加这一行:export PATH=/usr/R-3.1.3/bin:$PATH
source /etc/profile
- 测试
>R
即可看到如下信息:
简单测试
ok!
R version 3.1.3 (2015-03-09) -- "Smooth Sidewalk" Copyright (C) 2015 The R Foundation for Statistical Computing Platform: x86_64-unknown-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. > x<-c(1,2,3) > y<-c(102,299,301) > model<-lm(y~x) > summary(model) Call: lm(formula = y ~ x) Residuals: 1 2 3 -32.5 65.0 -32.5 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 35.00 121.60 0.288 0.822 x 99.50 56.29 1.768 0.328 Residual standard error: 79.61 on 1 degrees of freedom Multiple R-squared: 0.7575, Adjusted R-squared: 0.5151 F-statistic: 3.124 on 1 and 1 DF, p-value: 0.3278 > proc.time() user system elapsed 0.300 0.024 97.456 >
时间: 2024-10-29 00:18:31