File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,11 @@ def _prefix_if_non_local_file_entry(
5959
6060
6161def _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
6569def _entry_validate (entry : Sequence [str ]) -> None :
Original file line number Diff line number Diff line change 44
55import pytest
66
7+ from pre_commit import envcontext
78from pre_commit .languages import r
89from testing .fixtures import make_config_from_repo
910from 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'
You can’t perform that action at this time.
0 commit comments