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

Isolate conda R from system user library. #65

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions recipe/0019-Disable-default-user-libraries.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 8c85f70505694dd181ef47a47896007b150f94c3 Mon Sep 17 00:00:00 2001
From: John Blischak <jdblischak@gmail.com>
Date: Thu, 13 Dec 2018 14:12:32 -0500
Subject: [PATCH] Disable default user libraries.

---
etc/Renviron.in | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/etc/Renviron.in b/etc/Renviron.in
index 49604e54c2..38efb63bb9 100644
--- a/etc/Renviron.in
+++ b/etc/Renviron.in
@@ -39,8 +39,8 @@ TAR=${TAR-'@TAR@'}
## System and compiler types.
R_SYSTEM_ABI='@R_SYSTEM_ABI@'

-@BUILD_AQUA_FALSE@R_LIBS_USER=${R_LIBS_USER-'~/R/@R_PLATFORM@-library/@MAJ_MIN_VERSION@'}
-@BUILD_AQUA_TRUE@R_LIBS_USER=${R_LIBS_USER-'~/Library/R/@MAJ_MIN_VERSION@/library'}
+#@BUILD_AQUA_FALSE@R_LIBS_USER=${R_LIBS_USER-'~/R/@R_PLATFORM@-library/@MAJ_MIN_VERSION@'}
+#@BUILD_AQUA_TRUE@R_LIBS_USER=${R_LIBS_USER-'~/Library/R/@MAJ_MIN_VERSION@/library'}

### Local Variables: ***
### mode: sh ***
--
2.17.1

12 changes: 12 additions & 0 deletions recipe/activate-r-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@ if [[ ! -z ${RSTUDIO_WHICH_R+x} ]]; then
export RSTUDIO_WHICH_R_PREV="$RSTUDIO_WHICH_R"
fi
export RSTUDIO_WHICH_R="$CONDA_PREFIX/bin/R"

# store existing R_LIBS_USER if the user has not set CONDA_KEEP_R_LIBS_USER
if [[ ! -z ${R_LIBS_USER+x} && -z ${CONDA_KEEP_R_LIBS_USER+x} ]]; then
export R_LIBS_USER_PREV="$R_LIBS_USER"
fi
unset R_LIBS_USER

# store existing R_LIBS if the user has not set CONDA_KEEP_R_LIBS
if [[ ! -z ${R_LIBS+x} && -z ${CONDA_KEEP_R_LIBS+x} ]]; then
export R_LIBS_PREV="$R_LIBS"
fi
unset R_LIBS
12 changes: 12 additions & 0 deletions recipe/deactivate-r-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,15 @@ if [[ ! -z ${RSTUDIO_WHICH_R_PREV+x} ]]; then
else
unset RSTUDIO_WHICH_R
fi

# restore pre-existing R_LIBS_USER
if [[ ! -z ${R_LIBS_USER_PREV+x} ]]; then
export R_LIBS_USER="$R_LIBS_USER_PREV"
unset R_LIBS_USER_PREV
fi

# restore pre-existing R_LIBS
if [[ ! -z ${R_LIBS_PREV+x} ]]; then
export R_LIBS="$R_LIBS_PREV"
unset R_LIBS_PREV
fi
9 changes: 8 additions & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ source:
- 0015-link-Xt-to-uuid.patch
- 0017-Check-for-changes-then-forcibly-mv-in-javareconf.in.patch
- 0018-Use-LAPACK_LDFLAGS-in-Rlapack_la_LIBADD.patch
- 0019-Disable-default-user-libraries.patch

build:
merge_build_host: True # [win]
number: 3
number: 4
rpaths:
- lib/R/lib/
- lib/
Expand Down Expand Up @@ -177,8 +178,14 @@ test:
- Rscript -e "stopifnot(capabilities('jpeg'), TRUE)"
- Rscript -e "stopifnot(capabilities('png'), TRUE)"
- if not exist %PREFIX%\\Lib\\R\\bin\\x64\\R.lib exit 1 # [win]
- Rscript test-isolation-setup.R
- Rscript test-isolation.R
- Rscript test-isolation-teardown.R
files:
- test-svg.R
- test-isolation-setup.R
- test-isolation.R
- test-isolation-teardown.R

about:
home: http://www.r-project.org/
Expand Down
16 changes: 16 additions & 0 deletions recipe/test-isolation-setup.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
print(.libPaths())
os <- .Platform$OS.type
major <- R.version$major
minor <- substr(1, 1, R.version$minor)
platform <- R.version$platform

if (os == "unix" || os == "windows") {
d <- sprintf("~/R/%s-library/%s.%s", platform, major, minor)
} else if (os == "darwin") {
d <- sprintf("~/Library/R/%s.%s/library/", major, minor)
}

d_exists <- dir.exists(d)
if (!d_exists) {
dir.create(d, recursive = TRUE)
}
24 changes: 24 additions & 0 deletions recipe/test-isolation-teardown.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
print(.libPaths())
os <- .Platform$OS.type
major <- R.version$major
minor <- substr(1, 1, R.version$minor)
platform <- R.version$platform

if (os == "unix" || os == "windows") {
d <- sprintf("~/R/%s-library/%s.%s", platform, major, minor)
} else if (os == "darwin") {
d <- sprintf("~/Library/R/%s.%s/library/", major, minor)
}

# There were 3 nested subdirectories added for every OS. Only remove if empty
if (length(dir(d)) == 0) {
unlink(d)
}
d <- dirname(d)
if (length(dir(d)) == 0) {
unlink(d)
}
d <- dirname(d)
if (length(dir(d)) == 0) {
unlink(d)
}
2 changes: 2 additions & 0 deletions recipe/test-isolation.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# There should only be one library directory for a local conda R installation
stopifnot(length(.libPaths()) == 1)