-
Notifications
You must be signed in to change notification settings - Fork 181
/
setup_R.sh
executable file
·102 lines (80 loc) · 3.13 KB
/
setup_R.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
## Update configuration files for R and install some libraries.
##
## The URL of the default repository for R packages written to Rprofile.site,
## refers to the CRAN environment variable or to the first argument of this script.
## In order of preference, first argument of the script, the CRAN variable.
## ex. https://cloud.r-project.org, https://cran.r-project.org
set -e
CRAN=${1:-${CRAN:-"https://cran.r-project.org"}}
PURGE_BUILDDEPS=${PURGE_BUILDDEPS:-"true"}
ARCH=$(uname -m)
# shellcheck source=/dev/null
source /etc/os-release
# a function to install apt packages only if they are not installed
function apt_install() {
if ! dpkg -s "$@" >/dev/null 2>&1; then
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
apt-get update
fi
apt-get install -y --no-install-recommends "$@"
fi
}
## mechanism to force source installs if we're using RSPM
CRAN_SOURCE=${CRAN/"__linux__/${UBUNTU_CODENAME}/"/""}
## source install if using RSPM and arm64 image
if [ "$ARCH" = "aarch64" ]; then
CRAN=$CRAN_SOURCE
fi
## Add a default CRAN mirror
echo "options(repos = c(CRAN = '${CRAN}'), download.file.method = 'libcurl')" >>"${R_HOME}/etc/Rprofile.site"
## Set HTTPUserAgent for RSPM (https://github.com/rocker-org/rocker/issues/400)
cat <<EOF >>"${R_HOME}/etc/Rprofile.site"
# https://docs.rstudio.com/rspm/admin/serving-binaries/#binaries-r-configuration-linux
options(HTTPUserAgent = sprintf("R/%s R (%s)", getRversion(), paste(getRversion(), R.version["platform"], R.version["arch"], R.version["os"])))
EOF
## Install OpenBLAS and hot-switching to it
## https://github.com/rocker-org/rocker-versioned2/issues/390
if ! dpkg -l | grep -q libopenblas-dev; then
apt_install libopenblas-dev
update-alternatives --set "libblas.so.3-${ARCH}-linux-gnu" "/usr/lib/${ARCH}-linux-gnu/openblas-pthread/libblas.so.3"
fi
## Install littler
if [ ! -x "$(command -v r)" ]; then
BUILDDEPS="libpcre2-dev \
libdeflate-dev \
liblzma-dev \
libbz2-dev \
zlib1g-dev \
libicu-dev"
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
apt-get update
fi
# shellcheck disable=SC2086
apt_install ${BUILDDEPS}
Rscript -e "install.packages(c('littler', 'docopt'), repos='${CRAN_SOURCE}')"
# Clean up
# shellcheck disable=SC2086
if [ "${PURGE_BUILDDEPS}" != "false" ]; then
apt-get remove --purge -y ${BUILDDEPS}
fi
apt-get autoremove -y
apt-get autoclean -y
fi
## Symlink littler and littler's installation scripts
ln -sf "${R_HOME}/site-library/littler/bin/r" /usr/local/bin/r
ln -sf "${R_HOME}/site-library/littler/examples/installGithub.r" /usr/local/bin/installGithub.r
## Use rocker scripts version install2.r if it exists
if [ -f "/rocker_scripts/bin/install2.r" ]; then
ln -sf /rocker_scripts/bin/install2.r /usr/local/bin/install2.r
else
ln -sf "${R_HOME}/site-library/littler/examples/install2.r" /usr/local/bin/install2.r
fi
# Clean up
rm -rf /var/lib/apt/lists/*
# Check the R info
echo -e "Check the littler info...\n"
r --version
echo -e "Check the R info...\n"
R -q -e "sessionInfo()"
echo -e "Setup R, done!"