Skip to content

Commit ba496b8

Browse files
better r path detection
1 parent 44687a3 commit ba496b8

File tree

1 file changed

+9
-2
lines changed
  • pre_commit/languages

1 file changed

+9
-2
lines changed

pre_commit/languages/r.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ def _prefix_if_non_local_file_entry(
5454
path = prefix.path(entry[1])
5555
return (path,)
5656

57+
def _rscript_exec():
58+
"""
59+
When invoked in a sub-process of R, use full path
60+
"""
61+
return os.path.join(os.getenv('R_HOME', ""), 'Rscript')
62+
5763

5864
def _entry_validate(entry: Sequence[str]) -> None:
5965
"""
@@ -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)