Skip to content

Commit 010f457

Browse files
committed
wip add basic code [skip ci]
1 parent 2d728b7 commit 010f457

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

src/r-dependent-packages/devcontainer-feature.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
],
1515
"default": "auto",
1616
"description": "Version of pak to install. By default, the stable version is installed if needed."
17-
}
17+
},
18+
"additionalRepositories": {
19+
"type": "string",
20+
"default": "",
21+
"description": "String passed to the `pak::repo_add()` function.",
22+
"proposals": [
23+
"",
24+
"rhub = 'https://r-hub.r-universe.dev', jeroen = 'https://jeroen.r-universe.dev'"
25+
]
26+
},
1827
}
1928
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
3+
PAK_VERSION=${PAKVERSION:-"auto"}
4+
ROOT=${ROOT:-"."}
5+
ADDITIONAL_REPOSITORIES=${ADDITIONALREPOSITORIES:-""}
6+
DEPENDENCIES=${DEPENDENCIES:-"all"}
7+
8+
USERNAME=${USERNAME:-${_REMOTE_USER}}
9+
10+
LIFECYCLE_SCRIPTS_DIR="/usr/local/share/rocker-devcontainer-features/r-dependent-packages/scripts"
11+
12+
set -e
13+
14+
if [ "$(id -u)" -ne 0 ]; then
15+
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
16+
exit 1
17+
fi
18+
19+
check_r() {
20+
if [ ! -x "$(command -v R)" ]; then
21+
echo "(!) Cannot run R. Please install R before installing this Feature."
22+
echo " Skip installation..."
23+
exit 0
24+
fi
25+
}
26+
27+
install_pak() {
28+
local version=$1
29+
30+
if [ "${version}" = "auto" ]; then
31+
if su "${USERNAME}" -c "R -s -e 'packageVersion(\"pak\")'" >/dev/null 2>&1; then
32+
echo "pak is already installed. Skip pak installation..."
33+
return
34+
else
35+
version="stable"
36+
fi
37+
fi
38+
39+
echo "Installing pak ${version}..."
40+
# shellcheck disable=SC2016
41+
su "${USERNAME}" -c 'R -q -e "install.packages(\"pak\", repos = sprintf(\"https://r-lib.github.io/p/pak/'"${version}"'/%s/%s/%s\", .Platform\$pkgType, R.Version()\$os, R.Version()\$arch))"'
42+
}
43+
44+
export DEBIAN_FRONTEND=noninteractive
45+
46+
# Set Lifecycle scripts
47+
mkdir -p "${LIFECYCLE_SCRIPTS_DIR}"
48+
sed \
49+
-e "s|@ROOT@|${ROOT}|" \
50+
-e "s|@REPOS@|${ADDITIONAL_REPOSITORIES}|" \
51+
-e "s|@DEPS@|${DEPENDENCIES}|" \
52+
lifecycle_script.sh >"${LIFECYCLE_SCRIPTS_DIR}/lifecycle_script.sh"
53+
54+
check_r
55+
install_pak "${PAK_VERSION}"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
Rscript -e \
4+
'pak::repo_add(@REPOS@);
5+
pak::local_install_deps("@ROOT@", dependencies = trimws(unlist(strsplit("@DEPS@", ","))))'

src/r-dependent-packages/oncreate.sh

Whitespace-only changes.

0 commit comments

Comments
 (0)