49.1 演示环境介绍
Rstudio版本1.0.153
操作系统:RedHat7.2
用sudo权限的ec2-user用户操作
R版本3.4.2
49.2 操作演示
编译器安装
sudo yum -y install gcc
sudo yum -y install gcc-c++
sudo yum -y install gcc-gfortran
配置Java的环境变量
JAVA_HOME=/usr/java/jdk1.7.0_67-cloudera
CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tool.jar:$CLASSPATH
PATH=$JAVA_HOME/bin:$PATH
安装R编译需要的依赖包
sudo yum -y install readline-devel
sudo yum -y install libXt-devel
sudo yum -y install bzip2-devel
sudo yum -y install xz-devel.x86_64
sudo yum -y install libcurl-devel
sudo yum -y install texinfo.x86_64 texlive-pdftex-doc.noarch tex texlive-scheme-basic
下载R源码至服务器
[ec2-user@ip-168-33-22-46 ~]$ wget https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/base/R-3/R-3.4.2.tar.gz
--2017-10-06 10:14:49-- https://mirrors.tuna.tsinghua.edu.cn/CRAN/src/base/R-3/R-3.4.2.tar.gz
…
2017-10-06 10:15:00 (6.85 MB/s) - ‘R-3.4.2.tar.gz’ saved [30255544/30255544]
[ec2-user@ip-168-33-22-46 ~]$
R-3.4.2.tar.gz压缩包解压至当前目录
[ec2-user@ip-168-33-22-46 ec2-user]# tar -zxvf R-3.4.2.tar.gz
进入R-3.4.2目录执行命令进行配置
[ec2-user@ip-168-33-22-46 ec2-user]# cd R-3.4.2
[ec2-user@ip-168-33-22-46 R-3.4.2]# sudo ./configure --prefix=/usr/local/R-3.4.2 --enable-R-shlib
配置成功后,执行如下命令进行编译并安装到指定目录
[ec2-user@ip-168-33-22-46 R-3.4.2]# sudo make && make install
编辑/etc/profile文件,在文件末尾增加如下内容
R_HOME=/usr/local/R-3.4.2
PATH=$R_HOME/bin:$PATH
使环境变量立即生效
[root@ip-168-33-22-46 R-3.4.2]# source /etc/profile
验证环境变量是否配置成功
[root@ip-168-33-22-46 R-3.4.2]# echo $R_HOME
[root@ip-168-33-22-46 R-3.4.2]# R
测试Rstudio代码运行效果
将test.R文件在Linux服务器上运行
library(sparklyr)
sc <- spark_connect(master = "local", spark_home = Sys.getenv("SPARK_HOME","/opt/cloudera/parcels/SPARK2/lib/spark2"))
count_lines <- function(sc, file) {
spark_context(sc) %>%
invoke("textFile", file, 1L) %>%
invoke("count")
}
count_lines(sc, "file:///home/ec2-user/aaa.txt")
spark_disconnect(sc)
print("Hello R")
在命令行运行test.R文件
[root@ip-168-33-22-46 ec2-user]# Rscript test.R
运行结果:
常见问题
常见问题1:
configure: error: in `/home/ec2-user/R-3.4.2':
configure: error: C++ preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details
解决方法:由于c++编译器的相关package没有安装导致
[ec2-user@ip-168-33-22-46 R-3.4.2]$ sudo yum install gcc-c++
常见问题2:
checking for main in -ltermcap... no
checking for main in -ltermlib... no
checking for rl_callback_read_char in -lreadline... no
configure: error: --with-readline=yes (default) and headers/libs are not available
解决方法:因为需要依赖readline-devel包
[ec2-user@ip-168-33-22-46 R-3.4.2]$ sudo yum -y install readline-devel
常见问题3:
checking for Fortran 77 libraries of fc...
checking how to get verbose linking output from gcc -std=gnu99... -v
checking for C libraries of gcc -std=gnu99... -L/usr/local/lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../.. -lgcc_s
checking for dummy main to link with Fortran 77 libraries... none
checking for Fortran 77 name-mangling scheme... configure: error: in `/home/ec2-user/R-3.4.2':
configure: error: cannot compile a simple Fortran program
See `config.log' for more details
解决方法:由于需要依赖gcc-gfortran包的缘故
[ec2-user@ip-168-33-22-46 R-3.4.2]$ sudo yum -y install gcc-gfortran
常见问题4:
checking for wctrans_t... yes
checking for mbstate_t... yes
checking for ICU... no
checking for X... no
configure: error: --with-x=yes (default) and X11 headers/libs are not available
解决方法:需要依赖libXt-devel包
[ec2-user@ip-168-33-22-46 R-3.4.2]$ sudo yum -y install libXt-devel
常见问题5:
checking whether bzip2 support suffices... yes
checking for lzma_version_number in -llzma... no
configure: error: "liblzma library and headers are required"
解决方法:
[ec2-user@ip-168-33-22-46 R-3.4.2]$ sudo yum -y install xz-devel.x86_64
常见问题6:
checking mmap support for zlib... yes
checking for BZ2_bzlibVersion in -lbz2... no
checking whether bzip2 support suffices... configure: error: bzip2 library and headers are required
解决方法:
[ec2-user@ip-168-33-22-46 R-3.4.2]$ sudo yum -y install bzip2-devel
常见问题7:
checking curl/curl.h presence... no
checking for curl/curl.h... no
configure: error: libcurl >= 7.22.0 library and headers are required with support for https
解决方法:
[ec2-user@ip-168-33-22-46 R-3.4.2]$ sudo yum -y install libcurl-devel
常见问题8:
configure: WARNING: you cannot build info or HTML versions of the R manuals
configure: WARNING: you cannot build PDF versions of the R manuals
configure: WARNING: you cannot build PDF versions of vignettes and help pages
解决方法:
<pre style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; color: rgb(51, 51, 51); font-size: 17px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; background-color: rgb(202, 230, 202);">[ec2-user@ip-172-31-26-102 R-3.4.2]**$** sudo yum -y install texinfo.x86_64 texlive-pdftex-doc.noarch tex texlive-scheme-basic</pre>
常见问题9:
<pre style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; color: rgb(51, 51, 51); font-size: 17px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; background-color: rgb(202, 230, 202);">configure: WARNING: neither inconsolata.sty nor zi4.sty found: PDF vignettes and package manuals will not be rendered optimally</pre>
解决方法:
下载inconsolata包
<pre style="margin: 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; overflow-wrap: break-word !important; color: rgb(51, 51, 51); font-size: 17px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial; background-color: rgb(202, 230, 202);">wget http://mirror.lzu.edu.cn/CTAN/fonts/inconsolata.zip </pre>
解压inconsolata.zip,将压缩包内容拷贝至/usr/share/texlive/texmf-dist/tex/latex
[ec2-user@ip-168-33-22-46 ~]$ unzip inconsolata.zip
[ec2-user@ip-168-33-22-46 ~]$ cd inconsolata
[ec2-user@ip-168-33-22-46 inconsolata]$ sudo scp -r * /usr/share/texlive/texmf-dist/tex/latex
执行命令刷新sty:sudo mktexlsr或者sudo texhash
[ec2-user@ip-168-33-22-46 inconsolata]$ sudo mktexlsr
mktexlsr: Updating /usr/share/texlive/texmf/ls-R...
mktexlsr: Updating /usr/share/texlive/texmf-config/ls-R...
mktexlsr: Updating /usr/share/texlive/texmf-dist/ls-R...
mktexlsr: Updating /usr/share/texlive/texmf-local///ls-R...
mktexlsr: Updating /usr/share/texlive/texmf-var/ls-R...
mktexlsr: Done.
大数据视频推荐:
CSDN
大数据语音推荐:
企业级大数据技术应用
大数据机器学习案例之推荐系统
自然语言处理
大数据基础
人工智能:深度学习入门到精通