5
5
:target: https://anaconda.org/pytask/pytask-r
6
6
7
7
.. image :: https://github.com/pytask-dev/pytask-r/workflows/Continuous%20Integration%20Workflow/badge.svg?branch=main
8
- :target: https://github.com/pytask-dev/pytask/actions?query=branch%3Amain
8
+ :target: https://github.com/pytask-dev/pytask-r /actions?query=branch%3Amain
9
9
10
10
.. image :: https://codecov.io/gh/pytask-dev/pytask-r/branch/main/graph/badge.svg
11
11
:target: https://codecov.io/gh/pytask-dev/pytask-r
18
18
pytask-r
19
19
========
20
20
21
- pytask-r allows you to run R scripts with pytask.
21
+ Run R scripts with pytask.
22
22
23
23
24
24
Installation
@@ -31,17 +31,17 @@ Install the plugin with
31
31
$ conda config --add channels conda-forge --add channels pytask
32
32
$ conda install pytask-r
33
33
34
- You also need to have R installed and ``Rscript `` on your command line. To test
35
- whether it is installed, type the following on the command line
34
+ You also need to have R installed and ``Rscript `` on your command line. Test it by
35
+ typing the following on the command line
36
36
37
37
.. code-block :: console
38
38
39
39
$ Rscript --help
40
40
41
41
If an error is shown instead of a help page, you can install R with ``conda `` by
42
- choosing either the normal R or Microsoft R Open (MRO). The command is one of the two
43
- following commands. (See `here <https://docs.anaconda.com/anaconda/user-guide/tasks/
44
- using-r-language> `_ for further explanation on Anaconda, R, and MRO.)
42
+ choosing either R or Microsoft R Open (MRO). Choose one of the two following commands.
43
+ (See `here <https://docs.anaconda.com/anaconda/user-guide/tasks/ using-r-language >`_
44
+ for further explanation on Anaconda, R, and MRO.)
45
45
46
46
.. code-block :: console
47
47
@@ -54,9 +54,9 @@ Or install install R from the official `R Project <https://www.r-project.org/>`_
54
54
Usage
55
55
-----
56
56
57
- Similarly to normal task functions which execute Python code, you also define tasks to
57
+ Similarly to normal task functions which execute Python code, you define tasks to
58
58
execute scripts written in R with Python functions. The difference is that the function
59
- body does not contain any logic, but the decorators tell pytask how to handle the task.
59
+ body does not contain any logic, but the decorator tells pytask how to handle the task.
60
60
61
61
Here is an example where you want to run ``script.r ``.
62
62
@@ -72,27 +72,27 @@ Here is an example where you want to run ``script.r``.
72
72
pass
73
73
74
74
Note that, you need to apply the ``@pytask.mark.r `` marker so that pytask-r handles the
75
- task. The first dependency is always treated as the executable script. With multiple
76
- dependencies it may look like this
75
+ task. The executable script must be the first dependency. Other dependencies can be
76
+ added after that.
77
77
78
78
.. code-block :: python
79
79
80
80
@pytask.mark.r
81
- @pytask.mark.depends_on (" script.r" , " input.rds" )
81
+ @pytask.mark.depends_on ([ " script.r" , " input.rds" ] )
82
82
@pytask.mark.produces (" out.rds" )
83
83
def task_run_r_script ():
84
84
pass
85
85
86
86
If you are wondering why the function body is empty, know that pytask-r replaces the
87
- body with an predefined internal function. See the section on implementation details for
87
+ body with a predefined internal function. See the section on implementation details for
88
88
more information.
89
89
90
90
91
91
Command Line Arguments
92
92
~~~~~~~~~~~~~~~~~~~~~~
93
93
94
- The decorator can be used to pass command line arguments to ``Rscript `` which is by
95
- default the only the ``--vanilla `` flag. If you want to pass arguments to the script via
94
+ The decorator can be used to pass command line arguments to ``Rscript `` which is, by
95
+ default, only the ``--vanilla `` flag. If you want to pass arguments to the script via
96
96
the command line, use
97
97
98
98
.. code-block :: python
@@ -115,7 +115,7 @@ Parametrization
115
115
~~~~~~~~~~~~~~~
116
116
117
117
You can also parametrize the execution of scripts, meaning executing multiple R scripts
118
- as well as passing different command line arguments to an R script.
118
+ as well as passing different command line arguments to the same R script.
119
119
120
120
The following task executes two R scripts which produce different outputs.
121
121
@@ -130,29 +130,30 @@ The following task executes two R scripts which produce different outputs.
130
130
131
131
132
132
If you want to pass different command line arguments to the same R script, you have to
133
- include the R decorator in the parametrization just like with
133
+ include the `` @pytask.mark.r `` decorator in the parametrization just like with
134
134
``@pytask.mark.depends_on `` and ``@pytask.mark.produces ``.
135
135
136
136
.. code-block :: python
137
137
138
138
@pytask.mark.depends_on (" script.r" )
139
- @pytask.mark.parametrize (" produces, r" , [(" out_1.rds" , 1 ), (" out_2.rds" , 2 )])
139
+ @pytask.mark.parametrize (
140
+ " produces, r" ,
141
+ [(" output_1.rds" , [" --vanilla" , 1 ]), (" output_2.rds" , [" --vanilla" , 2 ])],
142
+ )
140
143
def task_execute_r_script ():
141
144
pass
142
145
143
146
144
- .. _implementation_details :
145
-
146
147
Implementation Details
147
148
----------------------
148
149
149
- The plugin is only a convenient wrapper around
150
+ The plugin is a convenient wrapper around
150
151
151
152
.. code-block :: python
152
153
153
154
import subprocess
154
155
155
- subprocess.run([" Rscript" , " --vanilla" , " script.r" ])
156
+ subprocess.run([" Rscript" , " --vanilla" , " script.r" ], check = True )
156
157
157
158
to which you can always resort to when the plugin does not deliver functionality you
158
159
need.
0 commit comments