Skip to content

Instantly share code, notes, and snippets.

@mokztk
Last active July 2, 2020 03:29
Show Gist options
  • Save mokztk/c802bb7a54ac5577d0a1a87c34ce79ce to your computer and use it in GitHub Desktop.
Save mokztk/c802bb7a54ac5577d0a1a87c34ce79ce to your computer and use it in GitHub Desktop.
ubuntu:18.04 に R 4.0.2+RStudio server+Radian と頻用パッケージを追加した作業用イメージ
# R 4.0.2 and RStudio server with some packages.
# MRAN library fixed at 2020-06-26 (the day 4.0.2 first came to MRAN)
FROM ubuntu:18.04
# Change environment to Japanese (Character, DateTime, and Fonts)
ENV DEBCONF_NOWARNINGS=yes
RUN set -x \
# install Japanese lung pack (and locales)
&& apt-get update \
&& apt-get install -y language-pack-ja-base language-pack-ja \
# locale settings
&& sed -i '$d' /etc/locale.gen \
&& echo "ja_JP.UTF-8 UTF-8" >> /etc/locale.gen \
&& locale-gen ja_JP.UTF-8 \
&& /usr/sbin/update-locale LANG=ja_JP.UTF-8 LANGUAGE="ja_JP:ja" \
&& /bin/bash -c "source /etc/default/locale" \
&& ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime \
# install CJK font
&& apt-get install -y fonts-noto-cjk \
# cleaning
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install R from MRAN snapshot
ENV MRAN="https://cran.microsoft.com/snapshot/2020-06-26"
RUN set -x \
# install essential packages
&& apt-get update \
&& apt-get install -y \
build-essential \
curl \
openssl \
ca-certificates \
gdebi-core \
psmisc \
python3-pip \
ssh \
git \
# install Microsoft IT SSL SHA2 CA Certificate
&& curl --output "msitwww2(1).crt" "http://www.microsoft.com/pki/mscorp/msitwww2(1).crt" \
&& openssl x509 -in "msitwww2(1).crt" -inform DER -out msitwww2.crt -outform PEM \
&& cp msitwww2.crt /usr/share/ca-certificates/ \
&& echo "msitwww2.crt" >> /etc/ca-certificates.conf \
&& update-ca-certificates \
&& rm *.crt \
# install latest version of R 4.0.2 (4.0.2-1.1804.0 / 2020-06-23)
&& echo "deb ${MRAN}/bin/linux/ubuntu bionic-cran40/" > /etc/apt/sources.list.d/cran.list \
&& apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 51716619E084DAB9 \
&& apt-get update \
&& apt-get install -y r-base littler \
# cleaning
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install frequently used packages
ENV R_INSTALL_STAGED=false
RUN set -x \
# install dependent packages
&& apt-get update \
&& apt-get install -y --no-install-recommends \
libcurl4-openssl-dev \
libssl-dev \
libxml2-dev \
libglu1-mesa-dev \
graphviz \
libgraphviz-dev \
libzmq3-dev \
# xorg \
libx11-dev \
libfreetype6-dev \
libfontconfig1-dev \
libcairo2-dev \
librsvg2-dev \
libmagick++-dev \
# install R-packages using 2020-06-26 MRAN snapshot
&& ln -s /usr/lib/R/site-library/littler/examples/install2.r /usr/local/bin/install2.r \
&& ln -s /usr/lib/R/site-library/littler/examples/installGithub.r /usr/local/bin/installGithub.r \
&& echo "options(repos = '${MRAN}')" > ~/.Rprofile \
&& Rscript -e "install.packages(c('docopt', 'BiocManager'))" \
&& Rscript -e "BiocManager::install(c('graph', 'Rgraphviz'))" \
&& install2.r --error --deps TRUE --ncpus -1 --skipinstalled \
xml2 \
devtools \
pacman \
tidyverse \
tidylog \
furrr \
RSQLite \
rmarkdown \
formatR \
caTools \
pROC \
cmprsk \
psych \
clinfun \
car \
MASS \
ggfortify \
ggsci \
tableone \
# since package "export" was removed from CRAN on 2020-02-21,
# install dev version from GitHub repo (commit d29650b / 2020-06-22)
officer \
rvg \
openxlsx \
flextable \
xtable\
rgl \
stargazer \
tikzDevice \
&& installGithub.r tomwenseleers/export@d29650b \
# cleaning
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install RStudio Server
RUN set -x \
&& apt-get update \
&& curl --output "rstudio-server.deb" https://download2.rstudio.org/server/bionic/amd64/rstudio-server-1.3.959-amd64.deb \
&& gdebi -n rstudio-server.deb \
&& rm *.deb \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
EXPOSE 8787
# Install radian: A 21 century R console
RUN set -x \
&& pip3 install -U radian
# User settings
RUN useradd -m rstudio \
&& echo "rstudio:rstudio" | chpasswd \
&& echo "r-libs-user=/usr/local/lib/R/site-library" >> /etc/rstudio/rsession.conf \
&& echo "r-cran-repos=${MRAN}" >> /etc/rstudio/rsession.conf \
&& echo "auth-timeout-minutes=0" >> /etc/rstudio/rserver.conf \
&& echo "options(repos = '${MRAN}')" > /home/rstudio/.Rprofile \
&& echo 'options(radian.color_scheme = "monokai")' > /home/rstudio/.radian_profile \
&& echo 'options(radian.auto_match = TRUE)' >> /home/rstudio/.radian_profile \
&& echo 'options(radian.prompt = "\033[0;32mr$>\033[0m ")' >> /home/rstudio/.radian_profile \
&& echo 'options(radian.escape_key_map = list(list(key = "m", value = " %>% ")))' >> /home/rstudio/.radian_profile \
&& chown rstudio:rstudio /home/rstudio \
&& addgroup rstudio staff \
&& mkdir /home/rstudio/.rstudio \
&& chown -R rstudio:rstudio /home/rstudio/.rstudio \
&& chown rstudio:rstudio /home/rstudio/.Rprofile \
&& chown rstudio:rstudio /home/rstudio/.radian_profile
WORKDIR /home/rstudio
ENV USER=rstudio \
HOME=/home/rstudio \
LANG=ja_JP.UTF-8 \
LC_ALL=ja_JP.UTF-8
# start RStudio server
#CMD rstudio-server start && tail -f /dev/null
CMD ["/usr/lib/rstudio-server/bin/rserver", "--server-daemonize=0"]
@mokztk
Copy link
Author

mokztk commented Jun 30, 2020

install.packages() と littler の install2.rdep(s) = TRUE の理解が間違っていたので、依存関係(Suggests)解決のためBioconductorからのインストールを先にした。R 4.0.0 までと挙動変わっている?

@mokztk
Copy link
Author

mokztk commented Jun 30, 2020

2020-06-26 は R 4.0.2 がMRANに登録された最初の日。
4.0.3 が出たら、いつものように 4.0.2 の最後の日で固定し直すか?

@mokztk
Copy link
Author

mokztk commented Jul 1, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment