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

Make language: r work when there is already a renv in the working directory and RENV_PROJECT is set #2170

Merged
merged 3 commits into from Dec 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions pre_commit/languages/r.py
Expand Up @@ -8,6 +8,7 @@

from pre_commit.envcontext import envcontext
from pre_commit.envcontext import PatchesT
from pre_commit.envcontext import UNSET
from pre_commit.hook import Hook
from pre_commit.languages import helpers
from pre_commit.prefix import Prefix
Expand All @@ -23,6 +24,7 @@
def get_env_patch(venv: str) -> PatchesT:
return (
('R_PROFILE_USER', os.path.join(venv, 'activate.R')),
('RENV_PROJECT', UNSET),
)


Expand Down Expand Up @@ -55,6 +57,10 @@ def _prefix_if_non_local_file_entry(
return (path,)


def _rscript_exec() -> str:
return os.path.join(os.getenv('R_HOME', ''), 'Rscript')


def _entry_validate(entry: Sequence[str]) -> None:
"""
Allowed entries:
Expand Down Expand Up @@ -95,8 +101,9 @@ def install_environment(
os.makedirs(env_dir, exist_ok=True)
shutil.copy(prefix.path('renv.lock'), env_dir)
shutil.copytree(prefix.path('renv'), os.path.join(env_dir, 'renv'))

cmd_output_b(
'Rscript', '--vanilla', '-e',
_rscript_exec(), '--vanilla', '-e',
f"""\
prefix_dir <- {prefix.prefix_dir!r}
options(
Expand Down Expand Up @@ -130,7 +137,7 @@ def install_environment(
if additional_dependencies:
with in_env(prefix, version):
cmd_output_b(
'Rscript', *RSCRIPT_OPTS, '-e',
_rscript_exec(), *RSCRIPT_OPTS, '-e',
'renv::install(commandArgs(trailingOnly = TRUE))',
*additional_dependencies,
cwd=env_dir,
Expand Down