R升级版本至4.1.1

升级背景

最近做项目,同事说目前R环境版本比较低(3.2.3),很多命令都不能使用,想着能不能更新到3.6.x以上。

查找资料

网上参考的文档为:

sudo su
# 添加地址
echo "deb http://www.stats.bris.ac.uk/R/bin/linux/ubuntu xenial-cran40/" >> /etc/apt/sources.list
# 添加CRAN存储密钥
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
# 更新软件源
apt-get update
apt-get upgrade

但是实际制作的时候会报错(截图为dockerfile运行截图),显示“从公钥服务器接受失败”
在这里插入图片描述
进而导致后续下载r-base、r-base-dev失败:
在这里插入图片描述

解决方法

继续查找方法,其实看了看,就是我在写密钥的时候,直接拿的别人的密钥,根据第一张图的提示,把密钥修改成我自己的,试试了成功了。

总结

最后整理一下我的代码如下:

#R更新源文件,添加密钥
RUN echo "deb http://www.stats.bris.ac.uk/R/bin/linux/ubuntu xenial-cran40/" >> /etc/apt/sources.list && \
    apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 51716619E084DAB9 && \
    apt-get update && \
    apt-get upgrade -y 

# 安装R基础版、开发版
RUN apt-get -y install r-base \
     r-base-dev \
     software-properties-common \
     python-software-properties

# 安装RStudio 
RUN wget https://download1.rstudio.org/rstudio-xenial-1.1.456-amd64.deb \
    && gdebi -n rstudio-xenial-1.1.456-amd64.deb \
    && rm -f rstudio-xenial-1.1.456-amd64.deb

#更换R的镜像源为阿里源,下载对应库,有的默认下载不了,加入repos
RUN echo "r <- getOption('repos'); r['CRAN'] <- 'http://mirrors.aliyun.com/CRAN/'; options(repos = r);" > ~/.Rprofile
RUN Rscript -e "install.packages('data.table')" \
        && Rscript -e "install.packages('Matrix')"  \
        && Rscript -e "install.packages('plyr')"  \
        && Rscript -e "install.packages('digest')"  \
        && Rscript -e "install.packages('gtable')"  \
        && Rscript -e "install.packages('reshape2')"  \
        && Rscript -e "install.packages('scales')"  \
        && Rscript -e "install.packages('proto')"  \
        && Rscript -e "install.packages('ggplot2')"  \
        && Rscript -e "install.packages('Hmisc')" \
        && Rscript -e "install.packages('maps')"  \
        && Rscript -e "install.packages('sp')"  \
        && Rscript -e "install.packages('maptools')"  \
        && Rscript -e "install.packages('corrplot')"  \
        && Rscript -e "install.packages('pROC')"  \
        && Rscript -e "install.packages('lubridate')" \
        && Rscript -e "install.packages('AER')" \
        && Rscript -e "install.packages('caret')"  \
        && Rscript -e "install.packages('readr')"  \
        && Rscript -e "install.packages('xgboost')"  \
        && Rscript -e "install.packages('R.utils')"  \
        && Rscript -e "install.packages('gridExtra')"  \
        && Rscript -e "install.packages('alrs')" \
        && Rscript -e "install.packages('nnet')"  \
        && Rscript -e "install.packages('e1071')"  \
        && Rscript -e "install.packages('jiebaRD')"  \
        && Rscript -e "install.packages('Rcpp')"  \
        && Rscript -e "install.packages('jiebaR')"  \
        && Rscript -e "install.packages('topicmodels')"  \
        && Rscript -e "install.packages('NLP')"  \
        && Rscript -e "install.packages('slam')"  \
        && Rscript -e "install.packages('tm')"  \
        && Rscript -e "install.packages('RColorBrewer')"  \
        && Rscript -e "install.packages('wordcloud')" \
        && Rscript -e "install.packages('lars')" \
        && Rscript -e "install.packages('tidyverse')" \
        && Rscript -e "install.packages('reshape2')" \
        && Rscript -e "install.packages('forecast')" \
        && Rscript -e "install.packages('e1071')" \
        && Rscript -e "install.packages('dygraphs')" \
        && Rscript -e "install.packages('ggplot2',repos='https://mran.microsoft.com/snapshot/2019-02-01/')" 

最后效果如下:
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值