Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[r-rig] Options to install devtools, jupyterlab, radian #52

Merged
merged 14 commits into from
Oct 9, 2022
5 changes: 5 additions & 0 deletions src/r-rig/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ $ R -q -e 'pak::pak("curl")'
ℹ Executing `sudo sh -c apt-get install -y libssl-dev`
✔ 1 pkg: kept 1 [11.8s]
```

## Python package installation

This feature has some options to install Python packages such as `jupyterlab`.
When installing Python packages, if `python3 -m pip` is not available, it will install `python3-pip` via apt.
19 changes: 17 additions & 2 deletions src/r-rig/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "R (via rig)",
"id": "r-rig",
"version": "0.5.0",
"version": "0.6.0",
"description": "Installs R, some R packages, and needed dependencies. Note: May require source code compilation for R packages.",
"documentationURL": "https://github.com/rocker-org/devcontainer-features/tree/main/src/r-rig",
"options": {
Expand All @@ -25,10 +25,25 @@
"default": "minimal",
"description": "Install R packages to make vscode-R work. lsp means the `languageserver` package, full means lsp plus the `httpgd` package."
},
"installDevTools": {
"type": "boolean",
"default": false,
"description": "Install the `devtools` R package."
},
"installRMarkdown": {
"type": "boolean",
"default": false,
"description": "Install the `rmarkdown` R package."
"description": "Install the `rmarkdown` R package. It is required for R Markdown or Quarto documentation."
},
"installJupyterlab": {
"type": "boolean",
"default": false,
"description": "Install and setup JupyterLab (via `python3 -m pip`). JupyterLab is a web-based interactive development environment for notebooks."
},
"installRadian": {
"type": "boolean",
"default": false,
"description": "Install radian (via `python3 -m pip`). radian is an R console with multiline editing and rich syntax highlight."
},
"pandocVersion": {
"type": "string",
Expand Down
62 changes: 61 additions & 1 deletion src/r-rig/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

R_VERSION=${VERSION:-"release"}
VSCODE_R_SUPPORT=${VSCODERSUPPORT:-"minimal"}
INSTALL_DEVTOOLS=${INSTALLDEVTOOLS:-"false"}
INSTALL_RMARKDOWN=${INSTALLRMARKDOWN:-"false"}
INSTALL_JUPYTERLAB=${INSTALLJUPYTERLAB:-"false"}
INSTALL_RADIAN=${INSTALLRADIAN:-"false"}
PANDOC_VERSION=${PANDOCVERSION:-"auto"}

USERNAME=${USERNAME:-"automatic"}

APT_PACKAGES=(curl ca-certificates)
PIP_PACKAGES=()
R_PACKAGES=()

set -e
Expand Down Expand Up @@ -56,6 +60,29 @@ elif [ "${VSCODE_R_SUPPORT}" = "full" ]; then
APT_PACKAGES+=(libxml2-dev libicu-dev libcairo2-dev libfontconfig1-dev libfreetype6-dev libpng-dev)
fi

if [ "${INSTALL_DEVTOOLS}" = "true" ]; then
APT_PACKAGES+=( \
make \
libgit2-dev \
libcurl4-openssl-dev \
libxml2-dev \
libssl-dev \
libfontconfig1-dev \
libharfbuzz-dev \
libfribidi-dev \
libfreetype6-dev \
libpng-dev \
libtiff-dev \
libjpeg-dev \
libicu-dev \
zlib1g-dev \
)
R_PACKAGES+=(devtools)
if [ "${PANDOC_VERSION}" = "auto" ] && [ ! -x "$(command -v pandoc)" ]; then
PANDOC_VERSION="latest"
fi
fi

if [ "${INSTALL_RMARKDOWN}" = "true" ]; then
APT_PACKAGES+=(make libicu-dev)
R_PACKAGES+=(rmarkdown)
Expand All @@ -64,6 +91,16 @@ if [ "${INSTALL_RMARKDOWN}" = "true" ]; then
fi
fi

if [ "${INSTALL_RADIAN}" = "true" ]; then
PIP_PACKAGES+=(radian)
fi

if [ "${INSTALL_JUPYTERLAB}" = "true" ]; then
APT_PACKAGES+=(libzmq3-dev)
PIP_PACKAGES+=(jupyterlab)
R_PACKAGES+=(IRkernel)
fi

if [ "${PANDOC_VERSION}" = "os-provided" ]; then
APT_PACKAGES+=(pandoc)
PANDOC_VERSION="none"
Expand Down Expand Up @@ -189,6 +226,20 @@ install_r_packages() {
fi
}

check_pip() {
if ! python3 -m pip --help >/dev/null 2>&1; then
check_packages python3-pip
fi
}

install_pip_packages() {
packages="$*"
if [ -n "${packages}" ]; then
check_pip
su ${USERNAME} -c "python3 -m pip install --user --upgrade --no-cache-dir --no-warn-script-location ${packages}"
fi
}

export DEBIAN_FRONTEND=noninteractive

# Clean up
Expand All @@ -200,6 +251,8 @@ fi

# shellcheck disable=SC2048 disable=SC2086
check_packages ${APT_PACKAGES[*]}
# shellcheck disable=SC2048 disable=SC2086
install_pip_packages ${PIP_PACKAGES[*]}

# Install pandoc if needed
if [ "${PANDOC_VERSION}" = "latest" ]; then
Expand Down Expand Up @@ -249,10 +302,17 @@ fi
echo "Install R packages..."
# Install the pak package
# shellcheck disable=SC2016
su ${USERNAME} -c 'R -q -e "install.packages(\"pak\", repos = sprintf(\"https://r-lib.github.io/p/pak/stable/%s/%s/%s\", .Platform\$pkgType, R.Version()\$os, R.Version()\$arch))"'
su ${USERNAME} -c 'R -q -e "install.packages(\"pak\", repos = sprintf(\"https://r-lib.github.io/p/pak/devel/%s/%s/%s\", .Platform\$pkgType, R.Version()\$os, R.Version()\$arch))"'
# shellcheck disable=SC2048 disable=SC2086
install_r_packages ${R_PACKAGES[*]}

# Set up IRkernel
if [ "${INSTALL_JUPYTERLAB}" = "true" ]; then
echo "Register IRkernel..."
# shellcheck disable=SC2016
su ${USERNAME} -c 'export PATH="/home/'${USERNAME}'/.local/bin:/root/.local/bin:${PATH}"; R -q -e "IRkernel::installspec()"'
fi

# Clean up
rm -rf /var/lib/apt/lists/*
rm -rf /tmp/rig
Expand Down
27 changes: 24 additions & 3 deletions test/_global/r_quarto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,30 @@ set -e
# Optional: Import test library bundled with the devcontainer CLI
source dev-container-features-test-lib

# Feature-specific tests
check "check for R" R -q -e "sessionInfo()"
check "check for quarto" quarto check all
cat <<"EOF" >/tmp/knitr.qmd
---
title: Test
engine: knitr
---

```{r}
cat("Hello Quarto!")
```
EOF

cat <<"EOF" >/tmp/jupyter.qmd
---
title: Test
engine: jupyter
---

```{r}
cat("Hello Quarto!")
```
EOF

# Feature-specific tests
check "check rendering (knitr)" quarto render /tmp/knitr.qmd
check "check rendering (jupyter)" quarto render /tmp/jupyter.qmd
# Report result
reportResults
3 changes: 2 additions & 1 deletion test/_global/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"image": "ubuntu:latest",
"features": {
"r-rig": {
"installRMarkdown": true
"installRMarkdown": true,
"installJupyterlab": true
},
"quarto-cli": {}
}
Expand Down
5 changes: 4 additions & 1 deletion test/r-rig/rpackages-source-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ source dev-container-features-test-lib

# Feature-specific tests
check "R" R -q -e "sessionInfo()"
check "rmarkdown" R -q -e 'rmarkdown::pandoc_version()'
check "languageserver" R -q -e 'names(installed.packages()[, 3])' | grep languageserver
check "httpgd" R -q -e 'names(installed.packages()[, 3])' | grep httpgd
check "devtools" R -q -e 'names(installed.packages()[, 3])' | grep devtools
check "rmarkdown" R -q -e 'rmarkdown::pandoc_version()'
check "jupyter" /root/.local/bin/jupyter kernelspec list | grep jupyter/kernels/ir
check "radian" /root/.local/bin/radian --version

# Report result
reportResults
8 changes: 6 additions & 2 deletions test/r-rig/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"features": {
"r-rig": {
"vscodeRSupport": "full",
"installRMarkdown": true
"installDevTools": true,
"installRMarkdown": true,
"installJupyterlab": true,
"installRadian": true
}
}
},
Expand Down Expand Up @@ -39,7 +42,8 @@
"features": {
"r-rig": {
"version": "none",
"installRMarkdown": true
"installRMarkdown": true,
"installJupyterlab": true
}
}
}
Expand Down