-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstallLib.sh
34 lines (25 loc) · 1.27 KB
/
installLib.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
#!/bin/bash
rinstall=0
while getopts "i" OPTION
do
case $OPTION in
i)
echo Running installLib with the option to install packages.
rinstall=1
;;
esac
done
rpath=$(Rscript -e "cat(.libPaths())")
library=$(cat $(find . -type f \( -name \*.R -o -name \*.Rmd \)) | sed -n 's/^library[(]\(.*\)[)]/\1/p' | tr "," "\n" | tr -d "[\"\\']" | sed "s/verbose\s*=\s*\(\(TRUE\)\|\(FALSE\)\)/ /g")
library+=$(cat $(find . -type f \( -name \*.R -o -name \*.Rmd \)) | sed -n 's/^require[(]\(.*\)[)]/ \1/p' | tr "," "\n" | tr -d "[\"\\']" | sed "s/verbose\s*=\s*\(\(TRUE\)\|\(FALSE\)\)/ /g")
library+=$(cat $(find . -type f \( -name \*.R -o -name \*.Rmd \)) | sed -n 's/^.*\@import\(From\)\?\s\([a-zA-Z]*\)\s.*/ \2/p')
library+=$(cat $(find . -type f \( -name \*.R -o -name \*.Rmd \)) | perl -e 's/(.*?)([[:alnum:]]+)(::)(.*?)|./ \2/g' | sed '/^\s*$/d')
installs=$(tr ' ' '\n' <<< "${library[@]}" | sort -u | tr '\n' ' ')
for onePkg in $installs; do
install=0
for paths in $rpath; do
test -d "$paths/$onePkg" && install=1
done
test $install -eq 0 && printf " The package %s hasn\'t been installed.\n" $onePkg
test $install -eq 0 && test $rinstall -eq 1 && printf " * Will now install the package.\n" && Rscript -e "install.packages (\"$onePkg\", repos=\"http://cran.r-project.org/\")"
done