From 0c985e4ae9a3431061d43f6a4cd5073235e67731 Mon Sep 17 00:00:00 2001 From: Raniere Gaia Costa da Silva Date: Wed, 9 Jul 2025 17:12:54 +0200 Subject: [PATCH 1/6] Add --vanilla to R call Closes https://github.com/jupyterhub/repo2docker/issues/1431 --- repo2docker/buildpacks/r.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/repo2docker/buildpacks/r.py b/repo2docker/buildpacks/r.py index ddc18ed3..e6b022a7 100644 --- a/repo2docker/buildpacks/r.py +++ b/repo2docker/buildpacks/r.py @@ -353,8 +353,8 @@ def get_build_scripts(self): # Install a pinned version of devtools, IRKernel and shiny rf""" export EXPANDED_CRAN_MIRROR_URL="$(. /etc/os-release && echo {cran_mirror_url} | envsubst)" && \ - R --quiet -e "install.packages(c('devtools', 'IRkernel', 'shiny'), repos=Sys.getenv(\"EXPANDED_CRAN_MIRROR_URL\"))" && \ - R --quiet -e "IRkernel::installspec(prefix=Sys.getenv(\"NB_PYTHON_PREFIX\"))" + R --vanilla --quiet -e "install.packages(c('devtools', 'IRkernel', 'shiny'), repos=Sys.getenv(\"EXPANDED_CRAN_MIRROR_URL\"))" && \ + R --vanilla --quiet -e "IRkernel::installspec(prefix=Sys.getenv(\"NB_PYTHON_PREFIX\"))" """, ), ] @@ -390,7 +390,7 @@ def get_preassemble_scripts(self): "${NB_USER}", # Delete /tmp/downloaded_packages only if install.R fails, as the second # invocation of install.R might be able to reuse them - f"Rscript {installR_path} && touch /tmp/.preassembled || true && rm -rf /tmp/downloaded_packages", + f"Rscript --vanilla {installR_path} && touch /tmp/.preassembled || true && rm -rf /tmp/downloaded_packages", ) ] @@ -408,14 +408,14 @@ def get_assemble_scripts(self): "${NB_USER}", # only run install.R if the pre-assembly failed # Delete any downloaded packages in /tmp, as they aren't reused by R - f"""if [ ! -f /tmp/.preassembled ]; then Rscript {installR_path}; rm -rf /tmp/downloaded_packages; fi""", + f"""if [ ! -f /tmp/.preassembled ]; then Rscript --vanilla {installR_path}; rm -rf /tmp/downloaded_packages; fi""", ) ] description_R = "DESCRIPTION" if not self.binder_dir and os.path.exists(description_R): assemble_scripts += [ - ("${NB_USER}", 'R --quiet -e "devtools::install_local(getwd())"') + ("${NB_USER}", 'R --vanilla --quiet -e "devtools::install_local(getwd())"') ] return assemble_scripts From 1da0de23900e8a2ecf062c9f35d0e57dbc279e3b Mon Sep 17 00:00:00 2001 From: Raniere Gaia Costa da Silva Date: Thu, 21 Aug 2025 17:21:59 +0200 Subject: [PATCH 2/6] Replace --vanilla with --no-init-file Closes https://github.com/jupyterhub/repo2docker/issues/1450 --- repo2docker/buildpacks/r.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/repo2docker/buildpacks/r.py b/repo2docker/buildpacks/r.py index e6b022a7..9b0f7376 100644 --- a/repo2docker/buildpacks/r.py +++ b/repo2docker/buildpacks/r.py @@ -353,8 +353,8 @@ def get_build_scripts(self): # Install a pinned version of devtools, IRKernel and shiny rf""" export EXPANDED_CRAN_MIRROR_URL="$(. /etc/os-release && echo {cran_mirror_url} | envsubst)" && \ - R --vanilla --quiet -e "install.packages(c('devtools', 'IRkernel', 'shiny'), repos=Sys.getenv(\"EXPANDED_CRAN_MIRROR_URL\"))" && \ - R --vanilla --quiet -e "IRkernel::installspec(prefix=Sys.getenv(\"NB_PYTHON_PREFIX\"))" + R --no-save --no-restore --no-init-file --no-environ --quiet -e "install.packages(c('devtools', 'IRkernel', 'shiny'), repos=Sys.getenv(\"EXPANDED_CRAN_MIRROR_URL\"))" && \ + R --no-save --no-restore --no-init-file --no-environ --quiet -e "IRkernel::installspec(prefix=Sys.getenv(\"NB_PYTHON_PREFIX\"))" """, ), ] @@ -390,7 +390,7 @@ def get_preassemble_scripts(self): "${NB_USER}", # Delete /tmp/downloaded_packages only if install.R fails, as the second # invocation of install.R might be able to reuse them - f"Rscript --vanilla {installR_path} && touch /tmp/.preassembled || true && rm -rf /tmp/downloaded_packages", + f"Rscript --no-save --no-restore --no-init-file --no-environ {installR_path} && touch /tmp/.preassembled || true && rm -rf /tmp/downloaded_packages", ) ] @@ -408,14 +408,17 @@ def get_assemble_scripts(self): "${NB_USER}", # only run install.R if the pre-assembly failed # Delete any downloaded packages in /tmp, as they aren't reused by R - f"""if [ ! -f /tmp/.preassembled ]; then Rscript --vanilla {installR_path}; rm -rf /tmp/downloaded_packages; fi""", + f"""if [ ! -f /tmp/.preassembled ]; then Rscript --no-save --no-restore --no-init-file --no-environ {installR_path}; rm -rf /tmp/downloaded_packages; fi""", ) ] description_R = "DESCRIPTION" if not self.binder_dir and os.path.exists(description_R): assemble_scripts += [ - ("${NB_USER}", 'R --vanilla --quiet -e "devtools::install_local(getwd())"') + ( + "${NB_USER}", + 'R --no-save --no-restore --no-init-file --no-environ --quiet -e "devtools::install_local(getwd())"', + ) ] return assemble_scripts From 36a2ed8b9e712b47b1872551135fda297f2eef43 Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 17 Apr 2026 16:15:35 -0700 Subject: [PATCH 3/6] R: install with pak devtools::install_local has been deprecated --- repo2docker/buildpacks/r.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repo2docker/buildpacks/r.py b/repo2docker/buildpacks/r.py index 9b0f7376..f98c2395 100644 --- a/repo2docker/buildpacks/r.py +++ b/repo2docker/buildpacks/r.py @@ -417,7 +417,7 @@ def get_assemble_scripts(self): assemble_scripts += [ ( "${NB_USER}", - 'R --no-save --no-restore --no-init-file --no-environ --quiet -e "devtools::install_local(getwd())"', + 'R --no-save --no-restore --no-init-file --no-environ --quiet -e "pak::local_install()"', ) ] From 229b117c2ef4fcaafafeb7289165e5068501f087 Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 17 Apr 2026 16:57:28 -0700 Subject: [PATCH 4/6] clear cache after pak install can't seem to _prevent_ writing cache --- repo2docker/buildpacks/r.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repo2docker/buildpacks/r.py b/repo2docker/buildpacks/r.py index f98c2395..00a712e6 100644 --- a/repo2docker/buildpacks/r.py +++ b/repo2docker/buildpacks/r.py @@ -417,7 +417,7 @@ def get_assemble_scripts(self): assemble_scripts += [ ( "${NB_USER}", - 'R --no-save --no-restore --no-init-file --no-environ --quiet -e "pak::local_install()"', + 'R --no-save --no-restore --no-init-file --no-environ --quiet -e "pak::local_install()" && rm -rf $HOME/.cache/R', ) ] From 6f4d8c4f5cc7bc65631ecd564ddcc505de74d1b9 Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 17 Apr 2026 17:38:39 -0700 Subject: [PATCH 5/6] manually cleanup after pak it leaves files in /tmp/ and ~/.cache/R/pkgcache/ --- repo2docker/buildpacks/r.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/repo2docker/buildpacks/r.py b/repo2docker/buildpacks/r.py index 00a712e6..0e1c88cf 100644 --- a/repo2docker/buildpacks/r.py +++ b/repo2docker/buildpacks/r.py @@ -350,10 +350,10 @@ def get_build_scripts(self): ), ( "${NB_USER}", - # Install a pinned version of devtools, IRKernel and shiny + # Install a pinned version of pak, devtools, IRKernel and shiny rf""" export EXPANDED_CRAN_MIRROR_URL="$(. /etc/os-release && echo {cran_mirror_url} | envsubst)" && \ - R --no-save --no-restore --no-init-file --no-environ --quiet -e "install.packages(c('devtools', 'IRkernel', 'shiny'), repos=Sys.getenv(\"EXPANDED_CRAN_MIRROR_URL\"))" && \ + R --no-save --no-restore --no-init-file --no-environ --quiet -e "install.packages(c('pak', 'devtools', 'IRkernel', 'shiny'), repos=Sys.getenv(\"EXPANDED_CRAN_MIRROR_URL\"))" && \ R --no-save --no-restore --no-init-file --no-environ --quiet -e "IRkernel::installspec(prefix=Sys.getenv(\"NB_PYTHON_PREFIX\"))" """, ), @@ -417,7 +417,10 @@ def get_assemble_scripts(self): assemble_scripts += [ ( "${NB_USER}", - 'R --no-save --no-restore --no-init-file --no-environ --quiet -e "pak::local_install()" && rm -rf $HOME/.cache/R', + # pak doesn't seem to cleanup after itself. + # pak::cache_clean() doesn't empty the cache, + # it leaves files in /tmp/Rabc123.../ and ~/.cache/R/pkg/... + 'R --no-save --no-restore --no-init-file --no-environ --quiet -e "pak::install_local()"; rm -rf $HOME/.cache/R; rm -rf /tmp/R*', ) ] From 27ecce6ebc9a45c4ca6f74ef5589c7e24d107d2f Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 17 Apr 2026 20:22:52 -0700 Subject: [PATCH 6/6] remotes doesn't leave a mess pak doesn't work if caches are cleaned --- repo2docker/buildpacks/r.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/repo2docker/buildpacks/r.py b/repo2docker/buildpacks/r.py index 0e1c88cf..4c77e591 100644 --- a/repo2docker/buildpacks/r.py +++ b/repo2docker/buildpacks/r.py @@ -350,10 +350,10 @@ def get_build_scripts(self): ), ( "${NB_USER}", - # Install a pinned version of pak, devtools, IRKernel and shiny + # Install a pinned version of remotes, devtools, IRKernel and shiny rf""" export EXPANDED_CRAN_MIRROR_URL="$(. /etc/os-release && echo {cran_mirror_url} | envsubst)" && \ - R --no-save --no-restore --no-init-file --no-environ --quiet -e "install.packages(c('pak', 'devtools', 'IRkernel', 'shiny'), repos=Sys.getenv(\"EXPANDED_CRAN_MIRROR_URL\"))" && \ + R --no-save --no-restore --no-init-file --no-environ --quiet -e "install.packages(c('remotes', 'devtools', 'IRkernel', 'shiny'), repos=Sys.getenv(\"EXPANDED_CRAN_MIRROR_URL\"))" && \ R --no-save --no-restore --no-init-file --no-environ --quiet -e "IRkernel::installspec(prefix=Sys.getenv(\"NB_PYTHON_PREFIX\"))" """, ), @@ -417,10 +417,7 @@ def get_assemble_scripts(self): assemble_scripts += [ ( "${NB_USER}", - # pak doesn't seem to cleanup after itself. - # pak::cache_clean() doesn't empty the cache, - # it leaves files in /tmp/Rabc123.../ and ~/.cache/R/pkg/... - 'R --no-save --no-restore --no-init-file --no-environ --quiet -e "pak::install_local()"; rm -rf $HOME/.cache/R; rm -rf /tmp/R*', + 'R --no-save --no-restore --no-init-file --no-environ --quiet -e "remotes::install_local()"', ) ]