@@ -98,6 +98,7 @@ for a ``"source"`` key in the dictionary and, secondly, under the key ``0``.
9898
9999.. code-block :: python
100100
101+ @pytask.mark.r
101102 @pytask.mark.depends_on ({" source" : " script.r" , " input" : " input.rds" })
102103 def task_run_r_script ():
103104 pass
@@ -106,6 +107,7 @@ for a ``"source"`` key in the dictionary and, secondly, under the key ``0``.
106107 # or
107108
108109
110+ @pytask.mark.r
109111 @pytask.mark.depends_on ({0 : " script.r" , " input" : " input.rds" })
110112 def task_run_r_script ():
111113 pass
@@ -114,6 +116,7 @@ for a ``"source"`` key in the dictionary and, secondly, under the key ``0``.
114116 # or two decorators for the function, if you do not assign a name to the input.
115117
116118
119+ @pytask.mark.r
117120 @pytask.mark.depends_on ({" source" : " script.r" })
118121 @pytask.mark.depends_on (" input.rds" )
119122 def task_run_r_script ():
@@ -123,13 +126,12 @@ for a ``"source"`` key in the dictionary and, secondly, under the key ``0``.
123126 Command Line Arguments
124127~~~~~~~~~~~~~~~~~~~~~~
125128
126- The decorator can be used to pass command line arguments to ``Rscript `` which is, by
127- default, only the ``--vanilla `` flag. If you want to pass arguments to the script via
128- the command line, use
129+ The decorator can be used to pass command line arguments to ``Rscript ``. See the
130+ following example.
129131
130132.. code-block :: python
131133
132- @pytask.mark.r ([ " --vanilla " , " value" ] )
134+ @pytask.mark.r (" value" )
133135 @pytask.mark.depends_on (" script.r" )
134136 @pytask.mark.produces (" out.rds" )
135137 def task_run_r_script ():
@@ -140,7 +142,7 @@ And in your ``script.r``, you can intercept the value with
140142.. code-block :: r
141143
142144 args <- commandArgs(trailingOnly=TRUE)
143- arg <- args[1] # ``arg`` holds ``"value"``
145+ arg <- args[1] # holds ``"value"``
144146
145147
146148 Parametrization
@@ -153,13 +155,23 @@ The following task executes two R scripts which produce different outputs.
153155
154156.. code-block :: python
155157
158+ from src.config import BLD , SRC
159+
160+
156161 @pytask.mark.r
157162 @pytask.mark.parametrize (
158- " depends_on, produces" , [(" script_1.r" , " 1.rds" ), (" script_2.r" , " 2.rds" )]
163+ " depends_on, produces" ,
164+ [(SRC / " script_1.r" , BLD / " 1.rds" ), (SRC / " script_2.r" , BLD / " 2.rds" )],
159165 )
160166 def task_execute_r_script ():
161167 pass
162168
169+ And the R script includes something like
170+
171+ .. code-block :: r
172+
173+ args <- commandArgs(trailingOnly=TRUE)
174+ produces <- args[1] # holds the path
163175
164176 If you want to pass different command line arguments to the same R script, you have to
165177include the ``@pytask.mark.r `` decorator in the parametrization just like with
@@ -170,10 +182,7 @@ include the ``@pytask.mark.r`` decorator in the parametrization just like with
170182 @pytask.mark.depends_on (" script.r" )
171183 @pytask.mark.parametrize (
172184 " produces, r" ,
173- [
174- (" output_1.rds" , ([" --vanilla" , " 1" ],)),
175- (" output_2.rds" , ([" --vanilla" , " 2" ],)),
176- ],
185+ [(BLD / " output_1.rds" , " 1" ), (BLD / " output_2.rds" , " 2" )],
177186 )
178187 def task_execute_r_script ():
179188 pass
@@ -199,7 +208,7 @@ The plugin is a convenient wrapper around
199208
200209 import subprocess
201210
202- subprocess.run([" Rscript" , " --vanilla " , " script.r" ], check = True )
211+ subprocess.run([" Rscript" , " script.r" ], check = True )
203212
204213 to which you can always resort to when the plugin does not deliver functionality you
205214need.
0 commit comments