/
install-save.sh
46 lines (43 loc) · 1.57 KB
/
install-save.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
# needs save lib pkg R_HOME
lib=$2
pkg=$3
R_HOME=$4
case $1 in
CHECK) if test -r install.R; then R_SAVE_IMAGE=true; else R_SAVE_IMAGE=false; fi;;
*) R_SAVE_IMAGE=$1;;
esac
export R_SAVE_IMAGE
## This is apparently needed, but no one told the Windows maintainers.
R_PACKAGE_NAME=${pkg}
export R_PACKAGE_NAME
if ${R_SAVE_IMAGE}; then
echo " save image"
save_image_defaults="list(compress=TRUE, safe=FALSE)"
code_file="${lib}/${pkg}/R/${pkg}"
rda_file="${lib}/${pkg}/R/all.rda"
if test -f NAMESPACE; then
code_cmd="echo saveNamespaceImage(\"${pkg}\", \"${rda_file}\", \"${lib}\")"
loader_file=nsrdaload.R
R_SAVE_EXE="${R_HOME}/bin/Rterm --slave --no-site-file --no-init-file"
else
code_cmd="cat ${code_file}"
loader_file=firstlib.R
R_SAVE_EXE="${R_HOME}/bin/Rterm --slave --save --no-site-file --no-init-file"
fi
(echo "options(save.image.defaults=${save_image_defaults})"; \
if test -s R_PROFILE.R; then cat R_PROFILE.R; fi; \
echo "invisible(.libPaths(c(\"${lib}\", .libPaths())))"; \
${code_cmd}) | ${R_SAVE_EXE} \
|| (echo "Execution of package source for ${pkg} failed"; exit 1)
if test ! -f NAMESPACE; then
mv .RData ${rda_file}
fi
mv "${code_file}" "${code_file}.R"
cat "${R_HOME}/share/R/${loader_file}" > "${code_file}"
## if install.R is non-empty, arrange to evaluate the R code it
## contains after the package source (maybe for some kind of
## cleanup).
if test -s install.R; then
cat install.R >> ${lib}/${pkg}/R/${pkg}
fi
fi