Skip to content
Open
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
50 changes: 23 additions & 27 deletions easybuild/easyblocks/generic/rpackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import pathlib
import re

import easybuild.tools.environment as env
from easybuild.easyblocks.r import EXTS_FILTER_R_PACKAGES, EB_R
from easybuild.easyblocks.generic.configuremake import check_config_guess, obtain_config_guess
from easybuild.framework.easyconfig import CUSTOM
Expand All @@ -52,16 +53,11 @@ def make_R_install_option(opt, values, cmdline=False):
"""
txt = ""
if values:
values_str = " ".join(values)
if cmdline:
txt = " --%s=\"%s" % (opt, values[0])
txt = f' --{opt}="{values_str}"'
else:
txt = "%s=c(\"%s" % (opt, values[0])
for i in values[1:]:
txt += " %s" % i
if cmdline:
txt += "\""
else:
txt += "\")"
txt = f'{opt}=c("{values_str}")'
return txt


Expand All @@ -81,7 +77,7 @@ def extra_options(extra_vars=None):
return extra_vars

def __init__(self, *args, **kwargs):
"""Initliaze RPackage-specific class variables."""
"""Initialize RPackage-specific class variables."""

super().__init__(*args, **kwargs)

Expand Down Expand Up @@ -130,17 +126,9 @@ def make_r_cmd(self, prefix=None):

def make_cmdline_cmd(self, prefix=None):
"""Create a command line to install an R package."""
confvars = ""
if self.configurevars:
confvars = make_R_install_option("configure-vars", self.configurevars, cmdline=True)
confargs = ""
if self.configureargs:
confargs = make_R_install_option("configure-args", self.configureargs, cmdline=True)

if prefix:
prefix = '--library=%s' % prefix
else:
prefix = ''
confvars = make_R_install_option("configure-vars", self.configurevars, cmdline=True)
confargs = make_R_install_option("configure-args", self.configureargs, cmdline=True)
prefix = make_R_install_option("library", [prefix], cmdline=True)

loc = self.start_dir
if loc is None:
Expand Down Expand Up @@ -173,9 +161,22 @@ def build_step(self):
"""No separate build step for R packages."""
pass

def set_R_user_vars(self):
"""Set R user environment variables to avoid writes to home directory."""
# set $R_LIBS_USER to non-existing path in build directory,
# to avoid picking up on R packages installed in home directory of current user
# (from ~/R/x86_64-pc-linux-gnu-library/<version>)
setvar('R_LIBS_USER', os.path.join(self.builddir, 'r_libs'))
# Avoid writes to $HOME via $XDG_CACHE_HOME, $R_USER_DATA_DIR etc
r_home = os.path.join(self.builddir, 'R_home')
for i in ('CACHE', 'CONFIG', 'DATA'):
path = os.path.join(r_home, i.lower())
env.setvar(f'XDG_{i}_HOME', path)
env.setvar(f'R_USER_{i}_DIR', path)

def install_R_package(self, cmd, inp=None):
"""Install R package as specified, and check for errors."""

self.set_R_user_vars()
res = run_shell_cmd(cmd, stdin=inp)
self.check_install_output(res.output)

Expand All @@ -187,7 +188,6 @@ def check_install_output(self, output):

if errors:
self.log.info("R package %s failed with error:\n%s", self.name, '\n'.join(errors))
self.handle_installation_errors()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was calling a non-existing method?!

Can't find any trace of this elsewhere, not even historically...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. It was probably intended in bac2514 but I'd guess the companion PR in framework wasn't added/used. Not sure where it was intended to be

cmd = "R -q --no-save"
stdin = """
remove.library(%s)
Expand Down Expand Up @@ -278,11 +278,7 @@ def prepare_r_ext_install(self):
:return: Shell command to run + string to pass to stdin.
"""

# set $R_LIBS_USER to non-existing path in build directory,
# to avoid picking up on R packages installed in home directory of current user
# (from ~/R/x86_64-pc-linux-gnu-library/<version>)
setvar('R_LIBS_USER', os.path.join(self.builddir, 'r_libs'))

self.set_R_user_vars()
# determine location
if isinstance(self.master, EB_R):
# extension is being installed as part of an R installation/module
Expand Down