@@ -31,34 +31,30 @@ You also need to have R installed and `Rscript` on your command line. Test it by
31
31
the following on the command line
32
32
33
33
``` console
34
- $ Rscript --help
34
+ Rscript --help
35
35
```
36
36
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 ` .
41
38
42
39
``` 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
45
41
```
46
42
47
43
Or install install R from the official [ R Project] ( https://www.r-project.org/ ) .
48
44
49
45
## Usage
50
46
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.
54
50
55
51
``` python
56
- import pytask
52
+ from pathlib import Path
53
+ from pytask import mark
57
54
58
55
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" )):
62
58
pass
63
59
```
64
60
@@ -68,10 +64,9 @@ more information.
68
64
69
65
### Dependencies and Products
70
66
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.
75
70
76
71
### Accessing dependencies and products in the script
77
72
@@ -99,10 +94,13 @@ To parse the JSON file, you need to install
99
94
You can also pass any other information to your script by using the ` @task ` decorator.
100
95
101
96
``` python
97
+ from pathlib import Path
98
+ from pytask import mark, task
99
+
100
+
102
101
@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" )):
106
104
pass
107
105
```
108
106
@@ -115,11 +113,11 @@ config$number # Is 1.
115
113
### Debugging
116
114
117
115
In 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
119
117
report of the task. It looks roughly like this
120
118
121
119
``` 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
123
121
```
124
122
125
123
### Command Line Arguments
@@ -128,9 +126,8 @@ The decorator can be used to pass command line arguments to `Rscript`. See the f
128
126
example.
129
127
130
128
``` 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" )):
134
131
pass
135
132
```
136
133
@@ -146,9 +143,8 @@ different outputs.
146
143
for i in range (2 ):
147
144
148
145
@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 " )):
152
148
pass
153
149
```
154
150
@@ -159,9 +155,8 @@ If you want to pass different inputs to the same R script, pass these arguments
159
155
for i in range (2 ):
160
156
161
157
@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 " )):
165
160
pass
166
161
```
167
162
@@ -189,11 +184,11 @@ supports YAML (if PyYaml is installed).
189
184
Use the ` serializer ` keyword arguments of the ` @pytask.mark.r ` decorator with
190
185
191
186
``` python
192
- @pytask. mark.r (script = " script.r" , serializer = " yaml" )
187
+ @mark.r (script = Path( " script.r" ) , serializer = " yaml" )
193
188
def task_example (): ...
194
189
```
195
190
196
- And in your R script use
191
+ And, in your R script use
197
192
198
193
``` r
199
194
library(yaml )
@@ -203,22 +198,22 @@ config <- read_yaml(args[length(args)])
203
198
204
199
Note that the ` YAML ` package needs to be installed.
205
200
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.
208
203
209
204
Here is a replication of the JSON example.
210
205
211
206
``` python
212
207
import json
213
208
214
209
215
- @pytask. mark.r (script = " script.r" , serializer = json.dumps, suffix = " .json" )
210
+ @mark.r (script = Path( " script.r" ) , serializer = json.dumps, suffix = " .json" )
216
211
def task_example (): ...
217
212
```
218
213
219
214
### Configuration
220
215
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.
222
217
223
218
** ` r_serializer ` **
224
219
0 commit comments