@@ -31,34 +31,30 @@ You also need to have R installed and `Rscript` on your command line. Test it by
3131the following on the command line
3232
3333``` console
34- $ Rscript --help
34+ Rscript --help
3535```
3636
37- If an error is shown instead of a help page, you can install R with ` conda ` by choosing
38- either R or Microsoft R Open (MRO). Choose one of the two following commands. (See
39- [ here] ( https://docs.anaconda.com/anaconda/user-guide/tasks/%20using-r-language ) for
40- further explanation on Anaconda, R, and MRO.)
37+ If an error is shown instead of a help page, you can install R with ` conda ` .
4138
4239``` console
43- $ conda install -c r r-base # For normal R.
44- $ conda install -c r mro-base # For MRO.
40+ conda install -c conda-forge r-base
4541```
4642
4743Or install install R from the official [ R Project] ( https://www.r-project.org/ ) .
4844
4945## Usage
5046
51- To create a task which runs a R script, define a task function with the ` @pytask. mark.r `
52- decorator. The ` script ` keyword provides an absolute path or path relative to the task
53- module to the R script .
47+ To create a task that runs an R script, define a task function with the ` @mark.r `
48+ decorator. The ` script ` keyword provides an absolute path or a path relative to the task
49+ module.
5450
5551``` python
56- import pytask
52+ from pathlib import Path
53+ from pytask import mark
5754
5855
59- @pytask.mark.r (script = " script.r" )
60- @pytask.mark.produces (" out.rds" )
61- def task_run_r_script ():
56+ @mark.r (script = Path(" script.r" ))
57+ def task_run_r_script (produces : Path = Path(" out.rds" )):
6258 pass
6359```
6460
@@ -68,10 +64,9 @@ more information.
6864
6965### Dependencies and Products
7066
71- Dependencies and products can be added as with a normal pytask task using the
72- ` @pytask.mark.depends_on ` and ` @pytask.mark.produces ` decorators. which is explained in
73- this
74- [ tutorial] ( https://pytask-dev.readthedocs.io/en/stable/tutorials/defining_dependencies_products.html ) .
67+ Dependencies and products can be added as usual. See this
68+ [ tutorial] ( https://pytask-dev.readthedocs.io/en/stable/tutorials/defining_dependencies_products.html )
69+ for some help.
7570
7671### Accessing dependencies and products in the script
7772
@@ -99,10 +94,13 @@ To parse the JSON file, you need to install
9994You can also pass any other information to your script by using the ` @task ` decorator.
10095
10196``` python
97+ from pathlib import Path
98+ from pytask import mark, task
99+
100+
102101@task (kwargs = {" number" : 1 })
103- @pytask.mark.r (script = " script.r" )
104- @pytask.mark.produces (" out.rds" )
105- def task_run_r_script ():
102+ @mark.r (script = Path(" script.r" ))
103+ def task_run_r_script (produces : Path = Path(" out.rds" )):
106104 pass
107105```
108106
@@ -115,11 +113,11 @@ config$number # Is 1.
115113### Debugging
116114
117115In case a task throws an error, you might want to execute the script independently from
118- pytask. After a failed execution, you see the command which executed the R script in the
116+ pytask. After a failed execution, you see the command that executed the R script in the
119117report of the task. It looks roughly like this
120118
121119``` console
122- $ Rscript < options> script.r < path-to> /.pytask/task_py_task_example.json
120+ Rscript <options> script.r <path-to>/.pytask/task_py_task_example.json
123121```
124122
125123### Command Line Arguments
@@ -128,9 +126,8 @@ The decorator can be used to pass command line arguments to `Rscript`. See the f
128126example.
129127
130128``` python
131- @pytask.mark.r (script = " script.r" , options = " --vanilla" )
132- @pytask.mark.produces (" out.rds" )
133- def task_run_r_script ():
129+ @mark.r (script = Path(" script.r" ), options = " --vanilla" )
130+ def task_run_r_script (produces : Path = Path(" out.rds" )):
134131 pass
135132```
136133
@@ -146,9 +143,8 @@ different outputs.
146143for i in range (2 ):
147144
148145 @task
149- @pytask.mark.r (script = f " script_ { i} .r " )
150- @pytask.mark.produces (f " out_ { i} .csv " )
151- def task_execute_r_script ():
146+ @mark.r (script = Path(f " script_ { i} .r " ))
147+ def task_execute_r_script (produces : Path = Path(f " out_ { i} .csv " )):
152148 pass
153149```
154150
@@ -159,9 +155,8 @@ If you want to pass different inputs to the same R script, pass these arguments
159155for i in range (2 ):
160156
161157 @task (kwargs = {" i" : i})
162- @pytask.mark.r (script = " script.r" )
163- @pytask.mark.produces (f " output_ { i} .csv " )
164- def task_execute_r_script ():
158+ @mark.r (script = Path(" script.r" ))
159+ def task_execute_r_script (produces : Path = Path(f " output_ { i} .csv " )):
165160 pass
166161```
167162
@@ -189,11 +184,11 @@ supports YAML (if PyYaml is installed).
189184Use the ` serializer ` keyword arguments of the ` @pytask.mark.r ` decorator with
190185
191186``` python
192- @pytask. mark.r (script = " script.r" , serializer = " yaml" )
187+ @mark.r (script = Path( " script.r" ) , serializer = " yaml" )
193188def task_example (): ...
194189```
195190
196- And in your R script use
191+ And, in your R script use
197192
198193``` r
199194library(yaml )
@@ -203,22 +198,22 @@ config <- read_yaml(args[length(args)])
203198
204199Note that the ` YAML ` package needs to be installed.
205200
206- If you need a custom serializer, you can also provide any callable to ` serializer ` which
207- transforms data to a string. Use ` suffix ` to set the correct file ending.
201+ If you need a custom serializer, you can also provide any callable ` serializer ` which
202+ transforms data into a string. Use ` suffix ` to set the correct file ending.
208203
209204Here is a replication of the JSON example.
210205
211206``` python
212207import json
213208
214209
215- @pytask. mark.r (script = " script.r" , serializer = json.dumps, suffix = " .json" )
210+ @mark.r (script = Path( " script.r" ) , serializer = json.dumps, suffix = " .json" )
216211def task_example (): ...
217212```
218213
219214### Configuration
220215
221- You can influence the default behavior of pytask-r with some configuration values.
216+ You can influence the default behavior of pytask-r with configuration values.
222217
223218** ` r_serializer ` **
224219
0 commit comments