Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0248dd4

Browse files
authored
Merge pull request pre-commit#2170 from lorenzwalthert/fix-renv-in-wd
Make `language: r` work when there is already a renv in the working directory and `RENV_PROJECT` is set
2 parents 44687a3 + 1617692 commit 0248dd4

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

  • pre_commit/languages

pre_commit/languages/r.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from pre_commit.envcontext import envcontext
1010
from pre_commit.envcontext import PatchesT
11+
from pre_commit.envcontext import UNSET
1112
from pre_commit.hook import Hook
1213
from pre_commit.languages import helpers
1314
from pre_commit.prefix import Prefix
@@ -23,6 +24,7 @@
2324
def get_env_patch(venv: str) -> PatchesT:
2425
return (
2526
('R_PROFILE_USER', os.path.join(venv, 'activate.R')),
27+
('RENV_PROJECT', UNSET),
2628
)
2729

2830

@@ -55,6 +57,10 @@ def _prefix_if_non_local_file_entry(
5557
return (path,)
5658

5759

60+
def _rscript_exec() -> str:
61+
return os.path.join(os.getenv('R_HOME', ''), 'Rscript')
62+
63+
5864
def _entry_validate(entry: Sequence[str]) -> None:
5965
"""
6066
Allowed entries:
@@ -95,8 +101,9 @@ def install_environment(
95101
os.makedirs(env_dir, exist_ok=True)
96102
shutil.copy(prefix.path('renv.lock'), env_dir)
97103
shutil.copytree(prefix.path('renv'), os.path.join(env_dir, 'renv'))
104+
98105
cmd_output_b(
99-
'Rscript', '--vanilla', '-e',
106+
_rscript_exec(), '--vanilla', '-e',
100107
f"""\
101108
prefix_dir <- {prefix.prefix_dir!r}
102109
options(
@@ -130,7 +137,7 @@ def install_environment(
130137
if additional_dependencies:
131138
with in_env(prefix, version):
132139
cmd_output_b(
133-
'Rscript', *RSCRIPT_OPTS, '-e',
140+
_rscript_exec(), *RSCRIPT_OPTS, '-e',
134141
'renv::install(commandArgs(trailingOnly = TRUE))',
135142
*additional_dependencies,
136143
cwd=env_dir,

0 commit comments

Comments
 (0)