r安装

这篇博客详细介绍了在Linux环境下安装R的过程,包括下载R包,解压,配置环境变量,安装依赖如readline-devel和libXt-devel,并特别提到了如果需要使用rJava,需要在配置阶段加上特定参数。同时,还提供了测试R安装是否成功的脚本创建与执行方法。此外,文中还提及了在R shell中安装rJava和devtools的步骤,为后续安装SparkR做准备。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.先安装JDK,我使用的是jdk1.7
2.下载r包https://cran.r-project.org/src/base/R-3/
3.解压:
tar -zxvf R-3.1.1.tar.gz
cd R-3.1.1
4.安装 (当然也可以跳过)
yum install readline-devel
yum install libXt-devel
./configure
这里写图片描述
5.安装
yum install readline-devel
yum install libXt-devel
./configure

如果使用rJava需要加上 –enable-R-shlib
./configure –enable-R-shlib –prefix=/usr/R-3.0.1
make
make install
6.配置环境变量
[root@hdp-gp-dk05 ~]#vi ~/.bash_profile
[root@hdp-gp-dk05 ~]#source ~/.bash_profile
7.测试:创建脚本(t.R)
cd /opt/script/R
vim t.R

#!/path/to/Rscript    #第一行

x<-c(1,2,3)    #R语言代码
y<-c(102,299,301)
model<-lm(y~x)
summary(model)

8、测试:执行脚本
R CMD BATCH –args /opt/script/R/t.R
more /opt/script/R/t.R #查看执行的结果
或者第二种方式
Rscript /opt/script/R/t.R #结果直接输出到终端
这里写图片描述

步骤1: 运行R Shell

bash# R

步骤2:在R shell中安装rJava

install.packages(“rJava”)

> install.packages("rJava")  
Warning in install.packages("rJava") :  
  'lib = "/usr/local/lib64/R/library"' is not writable  
Would you like to use a personal library instead?  (y/n) y  
Would you like to create a personal library  
~/R/x86_64-unknown-linux-gnu-library/3.1  
to install packages into?  (y/n) y  
--- Please select a CRAN mirror for use in this session ---  
CRAN mirror   

  1: 0-Cloud [https]                2: 0-Cloud                      
  3: Algeria                        4: Argentina (La Plata)         
  5: Australia (Canberra)           6: Australia (Melbourne)        
  7: Austria [https]                8: Austria                      
  9: Belgium (Antwerp)             10: Belgium (Ghent)              
 11: Brazil (BA)                   12: Brazil (PR)                  
 13: Brazil (RJ)                   14: Brazil (SP 1)                
 15: Brazil (SP 2)                 16: Canada (BC)                  
 17: Canada (NS)                   18: Canada (ON)                  
 19: Chile [https]                 20: Chile                        
 21: China (Beijing 2)             22: China (Beijing 3)            
 23: China (Beijing 4) [https]     24: China (Beijing 4)
    选择21
Selection: 21  
trying URL 'http://mirror.bjtu.edu.cn/cran/src/contrib/rJava_0.9-7.tar.gz'  
Content type 'application/octet-stream' length 711181 bytes (694 Kb)  
opened URL  
==================================================  
downloaded 694 Kb  

* installing *source* package ‘rJava’ ...  
** package ‘rJava’ successfully unpacked and MD5 sums checked  
checking for gcc... gcc -std=gnu99  
checking whether the C compiler works... yes  
checking for C compiler default output file name... a.out  
checking for suffix of executables...   
checking whether we are cross compiling... no  
checking for suffix of object files... o  
checking whether we are using the GNU C compiler... yes  
checking whether gcc -std=gnu99 accepts -g... yes  
checking for gcc -std=gnu99 option to accept ISO C89... none needed  
checking how to run the C preprocessor... gcc -std=gnu99 -E  
checking for grep that handles long lines and -e... /bin/grep  
checking for egrep... /bin/grep -E  
checking for ANSI C header files... yes  
checking for sys/wait.h that is POSIX.1 compatible... yes  
checking for sys/types.h... yes  
checking for sys/stat.h... yes  
checking for stdlib.h... yes  
checking for string.h... yes  
checking for memory.h... yes  
checking for strings.h... yes  
checking for inttypes.h... yes  
checking for stdint.h... yes  
checking for unistd.h... yes  
checking for string.h... (cached) yes  
checking sys/time.h usability... yes  
checking sys/time.h presence... yes  
checking for sys/time.h... yes  
checking for unistd.h... (cached) yes  
checking for an ANSI C-conforming const... yes  
checking whether time.h and sys/time.h may both be included... yes  
configure: checking whether gcc -std=gnu99 supports static inline...  
yes  
checking whether setjmp.h is POSIX.1 compatible... yes  
checking whether sigsetjmp is declared... yes  
checking whether siglongjmp is declared... yes  
checking Java support in R... present:  
interpreter : '/home/jifeng/jdk1.7.0_79/jre/bin/java'  
archiver    : '/home/jifeng/jdk1.7.0_79/bin/jar'  
compiler    : '/home/jifeng/jdk1.7.0_79/bin/javac'  
header prep.: '/home/jifeng/jdk1.7.0_79/bin/javah'  
cpp flags   : '-I/home/jifeng/jdk1.7.0_79/include -I/home/jifeng/jdk1.7.0_79/include/linux'  

步骤3: 在R shell中安装devtools

install.packages(“devtools”)

> install.packages("devtools")  
Installing package into ‘/home/jifeng/R/x86_64-unknown-linux-gnu-library/3.1’  
(as ‘lib’ is unspecified)  
also installing the dependencies ‘stringi’, ‘magrittr’, ‘BH’, ‘mime’, ‘R6’, ‘stringr’, ‘brew’, ‘Rcpp’, ‘xml2’, ‘httr’, ‘curl’, ‘memoise’, ‘whisker’, ‘evaluate’, ‘digest’, ‘rstudioapi’, ‘jsonlite’, ‘roxygen2’, ‘rversions’, ‘git2r’  

trying URL 'http://mirror.bjtu.edu.cn/cran/src/contrib/stringi_0.5-5.tar.gz'  
Content type 'application/octet-stream' length 3639183 bytes (3.5 Mb)  
opened URL  
==================================================  
downloaded 3.5 Mb  

trying URL 'http://mirror.bjtu.edu.cn/cran/src/contrib/magrittr_1.5.tar.gz'  
Content type 'application/octet-stream' length 200504 bytes (195 Kb)  
opened URL  
===========================
* installing *source* package ?.evtools?....
** package ?.evtools?.successfully unpacked and MD5 sums checked
** libs
gcc -std=gnu99 -I/usr/local/lib64/R/include -DNDEBUG  -I/usr/local/include    -fpic  -g -O2  -c devtools.c -o devtools.o
gcc -std=gnu99 -shared -L/usr/local/lib64 -o devtools.so devtools.o
installing to /usr/local/lib64/R/library/devtools/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (devtools)

The downloaded source packages are in
    ?.tmp/Rtmp1sc03a/downloaded_packages?
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done

步骤: 安装好rJava及devtools,接下来安装SparkR

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值