Skip to content

Commit e11163d

Browse files
authored
Merge pull request #2301 from jeff-m-sullivan/rscript-path
use Rscript path relative to $R_HOME/bin/...
2 parents d650160 + 764a0db commit e11163d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pre_commit/languages/r.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ def _prefix_if_non_local_file_entry(
5959

6060

6161
def _rscript_exec() -> str:
62-
return os.path.join(os.getenv('R_HOME', ''), 'Rscript')
62+
r_home = os.environ.get('R_HOME')
63+
if r_home is None:
64+
return 'Rscript'
65+
else:
66+
return os.path.join(r_home, 'bin', 'Rscript')
6367

6468

6569
def _entry_validate(entry: Sequence[str]) -> None:

tests/languages/r_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66

7+
from pre_commit import envcontext
78
from pre_commit.languages import r
89
from testing.fixtures import make_config_from_repo
910
from testing.fixtures import make_repo
@@ -129,3 +130,14 @@ def test_r_parsing_file_local(tempdir_factory, store):
129130
config=config,
130131
expect_path_prefix=False,
131132
)
133+
134+
135+
def test_rscript_exec_relative_to_r_home():
136+
expected = os.path.join('r_home_dir', 'bin', 'Rscript')
137+
with envcontext.envcontext((('R_HOME', 'r_home_dir'),)):
138+
assert r._rscript_exec() == expected
139+
140+
141+
def test_path_rscript_exec_no_r_home_set():
142+
with envcontext.envcontext((('R_HOME', envcontext.UNSET),)):
143+
assert r._rscript_exec() == 'Rscript'

0 commit comments

Comments
 (0)