11import copy
22import functools
33import subprocess
4+ from typing import Iterable
5+ from typing import Optional
6+ from typing import Union
47
5- import pytask
6- from pytask .mark import get_markers_from_task
7- from pytask .mark import has_marker
8- from pytask .nodes import PythonFunctionTask
9- from pytask .parametrize import _copy_func
10- from pytask .shared import to_list
8+ from _pytask .config import hookimpl
9+ from _pytask .mark import get_specific_markers_from_task
10+ from _pytask .mark import has_marker
11+ from _pytask .nodes import PythonFunctionTask
12+ from _pytask .parametrize import _copy_func
13+ from _pytask .shared import to_list
14+
15+
16+ def r (options : Optional [Union [str , Iterable [str ]]] = None ):
17+ """Specify command line options for Rscript.
18+
19+ Parameters
20+ ----------
21+ options : Optional[Union[str, Iterable[str]]]
22+ One or multiple command line options passed to Rscript.
23+
24+ """
25+ if options is None :
26+ options = ["--vanilla" ]
27+ elif isinstance (options , str ):
28+ options = [options ]
29+ return options
1130
1231
1332def run_r_script (depends_on , r ):
1433 script = to_list (depends_on )[0 ]
1534 subprocess .run (["Rscript" , script .as_posix (), * r ])
1635
1736
18- @pytask . hookimpl
37+ @hookimpl
1938def pytask_collect_task (session , path , name , obj ):
2039 """Collect a task which is a function.
2140
@@ -29,7 +48,7 @@ def pytask_collect_task(session, path, name, obj):
2948 path , name , obj , session
3049 )
3150 r_function = _copy_func (run_r_script )
32- r_function .pytestmark = copy .deepcopy (task .function .pytestmark )
51+ r_function .pytaskmark = copy .deepcopy (task .function .pytaskmark )
3352
3453 args = _create_command_line_arguments (task )
3554 r_function = functools .partial (r_function , r = args )
@@ -46,10 +65,11 @@ def pytask_collect_task(session, path, name, obj):
4665
4766
4867def _create_command_line_arguments (task ):
49- args = get_markers_from_task (task , "r" )[0 ].args
50- if args :
51- out = list (args )
52- else :
53- out = ["--vanilla" ]
68+ r_marks = get_specific_markers_from_task (task , "r" )
69+ mark = r_marks [0 ]
70+ for mark_ in r_marks [1 :]:
71+ mark = mark .combine_with (mark_ )
72+
73+ options = r (* mark .args , ** mark .kwargs )
5474
55- return out
75+ return options
0 commit comments