50.1 演示环境介绍
Linux已安装Apache2服务并正常运行
已安装完成R并正常使用
RedHat版本:7.2
用sudo权限的ec2-user用户操作
R版本:3.4.2
50.2 操作演示
R的Package安装主要分为在线安装和离线安装两种方式。
- 在线安装
- 在R的控制台输入install.packages(“vortexRdata”),操作如下
[ec2-user@ip-168-33-22-46 ~]$ R
...
> install.packages("vortexRdata")
Installing package into ‘/home/ec2-user/R/x86_64-pc-linux-gnu-library/3.4’
(as ‘lib’ is unspecified)
trying URL 'https://mirror.las.iastate.edu/CRAN/src/contrib/vortexRdata_1.0.3.tar.gz'
Content type 'application/x-gzip' length 1049418 bytes (1.0 MB)
==================================================
downloaded 1.0 MB
* installing *source* package ‘vortexRdata’ ...
** package ‘vortexRdata’ successfully unpacked and MD5 sums checked
…
* DONE (vortexRdata)
The downloaded source packages are in
‘/tmp/RtmpZC62NA/downloaded_packages’
>
- 离线安装
- 在Linux下通过命令行的方式安装离线包
- 首先下载需要安装的Package包
[ec2-user@ip-172-31-26-102 bin]$ sudo wget https://mirror.las.iastate.edu/CRAN/src/contrib/vortexRdata_1.0.3.tar.gz
执行R的命令进行离线安装
[ec2-user@ip-172-31-26-102 bin]$ sudo sh R CMD INSTALL vortexRdata_1.0.3.tar.gz
* installing to library ‘/usr/local/R-3.4.2/lib64/R/library’
* installing *source* package ‘vortexRdata’ ...
** package ‘vortexRdata’ successfully unpacked and MD5 sums checked
...
* DONE (vortexRdata)
[ec2-user@ip-172-31-26-102 bin]$
在Apache2的部署目录创建目录
[ec2-user@ip-172-31-22-86 html]$ sudo mkdir -p /var/www/html/src/contrib
将官网公有源的PACKAGES文件下载至/var/www/html/src/contrib目录
[ec2-user@ip-172-31-22-86 html]$ cd /var/www/html/src/contrib/
[ec2-user@ip-172-31-22-86 contrib]$ pwd
/var/www/html/src/contrib
[ec2-user@ip-172-31-22-86 contrib]$ sudo wget https://cran.rstudio.com/src/contrib/PACKAGES
…
Saving to: ‘PACKAGES.1’
100%[=====================================================================================>] 1,790,180 --.-K/s in 0.04s
2017-10-08 04:13:11 (46.5 MB/s) - ‘PACKAGES.1’ saved [1790180/1790180]
[ec2-user@ip-172-31-22-86 contrib]$
将官网上的依赖包下载至/var/www/html/src/contrib目录与PACKAGES同目录
<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-22-86 contrib]**$** pwd /var/www/html/src/contrib
[ec2-user@ip-172-31-22-86 contrib]**$** sudo wget https://mirror.las.iastate.edu/CRAN/src/contrib/vortexRdata_1.0.3.tar.gz</pre>
确保PACKAGES文件中有该包的描述信息,如下:
Package: vortexRdata
Version: 1.0.3
Depends: R (>= 3.1.0)
License: GPL-3
NeedsCompilation: no
- 在$R_HOME/ lib64/R/etc目录下增加配置文件Rprofile.site
- 在Rprofile.site文件中增加如下内容:
[root@ip-168-33-22-46 etc]# vim Rprofile.site
# Site R configuration.
local({
r <- getOption("repos")
r["CRAN"] <- "http://ip-172-31-22-86.ap-southeast-1.compute.internal/"
options(repos = r)
})
- 进入R控制台,执行包安装命令
- 就可以看到在安装包的时候是通过自己搭建的源下载。
[ec2-user@ip-168-33-22-46 etc]$ R
R version 3.4.2 (2017-09-28) -- "Short Summer"
...
> install.packages("vortexRdata")
Installing package into ‘/home/ec2-user/R/x86_64-pc-linux-gnu-library/3.4’
(as ‘lib’ is unspecified)
trying URL 'http://ip-172-31-22-86.ap-southeast-1.compute.internal/src/contrib/vortexRdata_1.0.3.tar.gz'
Content type 'application/x-gzip' length 1049418 bytes (1.0 MB)
==================================================
downloaded 1.0 MB
* installing *source* package ‘vortexRdata’ ...
** package ‘vortexRdata’ successfully unpacked and MD5 sums checked
...
* DONE (vortexRdata)
The downloaded source packages are in
‘/tmp/RtmpMH8iOW/downloaded_packages’
>
大数据视频推荐:
CSDN
大数据语音推荐:
企业级大数据技术应用
大数据机器学习案例之推荐系统
自然语言处理
大数据基础
人工智能:深度学习入门到精通