1.安装R
在 /etc/apt/sources中添加源
sudo vim /etc/apt/sources.list
在sources.list文件的最后一行为系统添加相应的镜像源
#(19.04)
deb https://cloud.r-project.org/bin/linux/ubuntu disco-cran35/
# (18.10)
deb https://cloud.r-project.org/bin/linux/ubuntu cosmic-cran35/
#(18.04;LTS)
deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/
#(16.04; LTS)
deb https://cloud.r-project.org/bin/linux/ubuntu xenial-cran35/
#(14.04; LTS)
deb https://cloud.r-project.org/bin/linux/ubuntu trusty-cran35/
更新软件源列表
sudo apt-get update
执行如下命令安装R语言:
sudo apt-get install r-base
系统会提示“您希望继续执行吗? [y/n]" ,可以直接从键盘输人y,然后按Enter键就可以了。只要遇到提问,都在键盘输人y后按Enter键即可。
旧版本的R安装时屏幕会显示“--在此连线阶段时请选用CRAN的镜子--”,并弹出一个白色背景的竖条形窗口,窗口标题是HTTPS CRAN mirros,标题下面列出了很多国家的镜像列表,可以选择位于China的镜像,例如,选择China( Bejing)[https],然后单击OK按钮,就可以开始安装。新版本的不会显示,可能是新版本默认设置为外国版本(我用的3.6.3版本的是这样)。安装过程需要几分钟时间,当然,安装过程所需时间,也和当前网络速度有关系。安装结束后,输入“R”启动R。
2.安装依赖库
为了完成可视化分析功能,需要为R安装一些依赖库,包括RMySQL、ggplot2、devtools和recharts。启动R进人R命令提示符状态,执行如下命令安装RMySQL:
> install.packages('RMySQL')
安装可能会出现以下错误:
Configure could not find suitable mysql/mariadb client library. Try installing:
* deb: libmariadbclient-dev | libmariadb-client-lgpl-dev (Debian, Ubuntu)
* rpm: mariadb-connector-c-devel | mariadb-devel | mysql-devel (Fedora, CentOS, RHEL)
* csw: mysql56_dev (Solaris)
* brew: mariadb-connector-c (OSX)
If you already have a mysql client library installed, verify that either
mariadb_config or mysql_config is on your PATH. If these are unavailable
you can also set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
如下图所示:
我们需要安装所欠缺的组件,也就是*deb:(红色横线)后面所显示的组件。执行下面命令安装:
sudo apt-get install libmariadb-client-lgpl-dev
然后再重新执行如下命令安装RMySQL:
> install.packages('RMySQL')
执行如下命令安装绘图包ggplot2:
> install.packages('ggplot2')
接下来继续运行下面命令安装devtools:
> install.packages('devtools')
安装时可能也会出现类似的错误:
Configuration failed because openssl was not found. Try installing:
* deb: libssl-dev (Debian, Ubuntu, etc)
* rpm: openssl-devel (Fedora, CentOS, RHEL)
* csw: libssl_dev (Solaris)
* brew: [email protected] (Mac OSX)
If openssl is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a openssl.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
--------------------------------------------------------------------
ERROR: configuration failed for package ‘openssl’
Configuration failed because libxml-2.0 was not found. Try installing:
* deb: libxml2-dev (Debian, Ubuntu, etc)
* rpm: libxml2-devel (Fedora, CentOS, RHEL)
* csw: libxml2_dev (Solaris)
If libxml-2.0 is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libxml-2.0.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
如下图:
同样的,我们安装*deb后面所缺少的组件即可,可能需要安装以下四个组件:
sudo apt-get install libssl-dev
sudo apt-get install libssh2-1-dev
sudo apt-get install libcurl4-openssl-dev
sudo apt-get install libxml2-dev
最后在R命令提示符下,再执行如下命令安装taiyun/ recharts :
> devtools::install_github('taiyun/recharts')
是的,还是会可能出现错误:
> devtools::install_github('taiyun/recharts')
错误: Failed to install 'unknown package' from GitHub:
Failed to connect to api.github.com port 443: 拒绝连接
安装R时我们说到新版本的R可能是默认使用外国的镜像,我们只需使用以下命令设置CRAN使用清华大学镜像即可:
options(repos=structure(c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/")))
接着重新安装taiyun/ recharts :
> devtools::install_github('taiyun/recharts')
至此,R可视化分析的安装工作完成。
参考链接:https://blog.csdn.net/m0_37601622/article/details/93135920
https://blog.csdn.net/qq_41858657/article/details/104707330
————————————————
版权声明:本文为CSDN博主「Wingkin-」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Wing_kin666/article/details/106020600