-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_missing.sh
23 lines (21 loc) · 1016 Bytes
/
install_missing.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash
set -x
QMD=$(realpath "$1")
echo $QMD
mkdir -p /tmp
# Extract missing R pkg or Python module from quarto error message
while ( quarto render $QMD --to html 3>&1 1>&2- 2>&3- ) | grep "there is no package called" > /tmp/rmissingpkg \
|| ( quarto render $QMD --to html 3>&1 1>&2- 2>&3- ) | grep "ModuleNotFoundError: No module named" > /tmp/pymissingmodule;
do
if [[ -s /tmp/rmissingpkg ]]; then
RPKG=$(awk '{print $NF}' /tmp/rmissingpkg)
# Install missing R package
Rscript -e "BiocManager::install('$(echo "${RPKG:1:${#RPKG}-2}" | sed "s/'//g")')" && rm /tmp/rmissingpkg
# Link reticulate with existing python3
if [ $RPKG == "'reticulate'" ]; then Rscript -e "library(reticulate); use_python('$(which python3)')"; fi
elif [[ -s /tmp/pymissingmodule ]]; then
PYMOD=$(awk '{print $NF}' /tmp/pymissingmodule | sed "s/'//g")
# Install missing python module
python3 -m pip install $PYMOD && rm /tmp/pymissingmodule
fi
done