You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here, we show how `devoptera` can be used to greatly accelerate your R package development workflow.
26
+
Here, we show how `devoptera` can be used to greatly accelerate your
27
+
R package development workflow.
27
28
28
29
## `source_all`
29
30
30
-
Let's say you have many functions in your *R* folder and want to have access to them all without having to write out the `pkg:::internal_func` notation. You can source all the functions at once by running `devoptera::source_all`.
31
+
Let's say you have many functions in your *R* folder and want to have
32
+
access to them all without having to write out the `pkg:::internal_func`
33
+
notation. You can source all the functions at once by running
34
+
`devoptera::source_all`.
31
35
32
-
Thus function can also load any R packages you need by supplying the
33
-
package names to the
36
+
This function can also load any R packages you need by supplying the
As a developer, how often do you find yourself realizing there's a bug somewhere inside your function. You could:
43
-
44
-
***`Strategy 2`: Edit --> Rebuild --> Repeat**: Make a change to the code, rebuild the package, and rerun the function as a whole. This most closely mimics how it will run in production, but is extremely slow when iterating this edit-rebuild process many, many times over.
45
-
***`Strategy 2`:Run internal code line-by-line**: Alternatively, you could go within your function, run one line of code at a time and inspect the variables it produces at each step. This is much faster than guessing whether your changes fixed the bug and rebuilding each time to find out whether they worked. But in order to do this, you first need to initialise each argument in your function as a global variable so that you can run the code line-by-line. But your function has many arguments, so now you spend the next minute(s) tediously making each argument into a variable of the same name (using the defaults as the assigned values).
46
-
47
-
`devoptera::args2vars` automates `Strategy 2` by first running `source_all` (from previous example) and then automatically assigning each of your function's arguments as global variables in your R environment.
48
-
Voila! No more tedious argument defining, allowing you to rapidly debug your code before going to rebuild the entire package.
49
-
50
-
### Define a function
46
+
As a developer, how often do you find yourself realizing there's a bug
47
+
somewhere inside your function? You could:
48
+
49
+
***Strategy 1: Edit --> Rebuild --> Repeat**: Make a change to the code,
50
+
rebuild the package, and rerun the function as a whole. This most closely
51
+
mimics how it will run in production, but is extremely slow when iterating
52
+
this edit-rebuild process many, many times over.
53
+
***Strategy 2: Run internal code line-by-line**: Alternatively, you could
54
+
go within your function, run one line of code at a time and inspect the
55
+
variables it produces at each step. This is much faster than guessing
56
+
whether your changes fixed the bug and rebuilding each time to find out
57
+
whether they worked. But in order to do this, you first need to initialise
58
+
each argument in your function as a global variable so that you can run the
59
+
code line-by-line. But your function has many arguments, so now you spend
60
+
the next minute(s) tediously making each argument into a variable of the
61
+
same name (using the defaults as the assigned values).
62
+
63
+
`devoptera::args2vars` automates **Strategy 2** by first running
64
+
`source_all` (from previous example) and then automatically assigning each
65
+
of your function's arguments as global variables in your R environment.
66
+
No more tedious argument defining, allowing you to rapidly debug your code
67
+
before going to rebuild the entire package.
68
+
69
+
### Define a function
51
70
52
71
Here we define an arbitrary function with 3 arguments.
53
-
If your function is already in one of your source files (i.e. a *.R* file within the *R/* subfolder), you can skip this step.
72
+
If your function is already in one of your source files (i.e. a *.R* file
73
+
within the *R/* subfolder), you can skip this step.
Now we will convert all the default arguments of `myfunc` to global variables. It also returns a named list with each variable's assigned value.
83
+
Now we will convert all the default arguments of `myfunc` to global
84
+
variables. It also returns a named list with each variable's assigned value.
64
85
65
86
```{r}
66
87
args <- devoptera::args2vars(myfunc)
@@ -72,75 +93,88 @@ After debugging your code, you can now proceed to the next steps.
72
93
73
94
### Clear
74
95
75
-
Remove all variables using `devoptera::rma()`,
76
-
or by clicking the little broom :broom: in the upper right of your `Environment` panel in RStudio.
96
+
Remove all variables using `devoptera::rma()`,
97
+
or by clicking the little broom in the upper right of your `Environment`
98
+
panel in RStudio.
77
99
78
-
This is important as it will ensure that the names of functions/variables in your global environment (created with `source_all`/`args2vars`) don't override the functions/variables within your reinstalled package (in the next step).
100
+
This is important as it will ensure that the names of functions/variables in
101
+
your global environment (created with `source_all`/`args2vars`) don't
102
+
override the functions/variables within your reinstalled package
103
+
(in the next step).
79
104
80
105
```{r}
81
106
devoptera::rma()
82
107
```
83
108
84
109
### Reinstall
85
110
86
-
(Re)install your package with `devoptera::install` (imported directly from `devtools::install`),
111
+
(Re)install your package with `devtools::install()`,
87
112
or by clicking the `Install` button within the `Build` panel in RStudio.
88
113
89
-
This function is equivalent to the keystrokes `CMD`+`SHIFT`+`B` within RStudio.
114
+
This is equivalent to the keystrokes `CMD`+`SHIFT`+`B` within RStudio.
90
115
91
116
```{r, eval=FALSE}
92
-
install()
117
+
devtools::install()
93
118
```
94
119
95
120
### Check
96
121
97
-
Now you can recheck your package as usual to make sure everything runs as expected.
122
+
Now you can recheck your package as usual to make sure everything runs
123
+
as expected.
98
124
99
125
#### [CRAN](https://cran.r-project.org/) checks
100
126
101
-
This `check` function is directly imported from `r `BiocStyle::CRANpkg('devtools')`.
127
+
The `check` function from `r BiocStyle::CRANpkg('devtools')` runs
128
+
`R CMD check` on your package.
102
129
103
-
This function is equivalent to the keystrokes `CMD`+`SHIFT`+`E` within RStudio.
130
+
This is equivalent to the keystrokes `CMD`+`SHIFT`+`E` within RStudio.
This `BiocCheck` function is directly imported from `r `Biocpkg::CRANpkg('BiocCheck')`.
138
+
The `BiocCheck` function from `r BiocStyle::Biocpkg('BiocCheck')` runs
139
+
additional Bioconductor-specific checks.
112
140
113
141
```{r, eval=FALSE}
114
-
BiocCheck()
142
+
BiocCheck::BiocCheck()
115
143
```
116
144
117
145
118
-
If you still run into some bugs or unexpected behaviour, don't worry!
119
-
You can still easily go back and repeat this process until everything is working smoothly.
146
+
If you still run into some bugs or unexpected behaviour, don't worry!
147
+
You can still easily go back and repeat this process until everything
148
+
is working smoothly.
120
149
121
150
# Extra functions
122
151
123
152
## Restarting R
124
153
125
-
Restarting your R session can be helpful or necessary in a variety of situations. Not only does it clear your variables, it unloads all packages which is necessary when you want to use a package you just installed a new version of.
154
+
Restarting your R session can be helpful or necessary in a variety of
155
+
situations. Not only does it clear your variables, it unloads all packages
156
+
which is necessary when you want to use a package you just installed
157
+
a new version of.
126
158
127
-
This function is equivalent to the keystrokes `CMD`+`SHIFT`+`0` within RStudio.
159
+
This is equivalent to the keystrokes `CMD`+`SHIFT`+`0` within RStudio.
128
160
129
161
```{r, eval=FALSE}
130
162
devoptera::restart()
131
163
```
132
164
133
-
134
165
135
-
# Session Info
166
+
# Session Info
136
167
137
-
It is best practice to always include your R Session Info in any Rmarkdown report or vignette. It contains information about which OS, R version, and R package versions you generated the report with.
168
+
It is best practice to always include your R Session Info in any
169
+
Rmarkdown report or vignette. It contains information about which OS,
170
+
R version, and R package versions you generated the report with.
138
171
139
-
`devoptera::session_info` provides a collapsible version of the Session Info, which can be helpful when Session Info is particularly long.
172
+
`devoptera::session_info` provides a collapsible version of the Session
173
+
Info, which can be helpful when Session Info is particularly long.
0 commit comments