1
- # ' Create documentation template for the R Markdown results report.
1
+ # ' Initialize documentation template for the R Markdown results report.
2
2
# '
3
- # ' @name create_doc_template
3
+ # ' @name init_docs
4
4
# ' @description Create documentation template (a series of .md files) to
5
5
# ' fill out for the R Markdown results report. If the \code{experiment} is
6
- # ' provided, the documentation files can be found in the \code{Experiment}'s
7
- # ' results directory (see \code{Experiment$get_save_dir()}) under docs/.
8
- # ' Otherwise, the documentation files can be found in the specified
6
+ # ' provided, the documentation files can be found in the \code{Experiment}'s
7
+ # ' results directory (see \code{Experiment$get_save_dir()}) under docs/.
8
+ # ' Otherwise, the documentation files can be found in the specified
9
9
# ' \code{save_dir} directory under docs/. The documentation files generated
10
- # ' include objectives.md and .md files corresponding to \code{DGPs},
11
- # ' \code{Methods}, \code{Evaluators}, and \code{Visualizers} in the
10
+ # ' include objectives.md and .md files corresponding to \code{DGPs},
11
+ # ' \code{Methods}, \code{Evaluators}, and \code{Visualizers} in the
12
12
# ' \code{Experiment}.
13
13
# '
14
14
# ' @param experiment An \code{Experiment} object. If provided, documentation is
15
- # ' created for all previously saved \code{Experiments} that are found in the
16
- # ' directory given by \code{experiment$get_save_dir()}. If no
17
- # ' \code{Experiments} have been previously saved under this directory, then
18
- # ' the current \code{experiment} is saved to disk and used to create the
19
- # ' documentation template.
15
+ # ' created for all previously saved \code{Experiments} that are found in the
16
+ # ' directory given by \code{experiment$get_save_dir()}. If no
17
+ # ' \code{Experiments} have been previously saved under this directory, then
18
+ # ' the current \code{experiment} is saved to disk and used to create the
19
+ # ' documentation template.
20
20
# ' @param save_dir An optional directory in which to find previously saved
21
21
# ' \code{Experiment} objects. Documentation is created for these found
22
22
# ' \code{Experiments}. Not used if \code{experiment} is provided.
23
23
# '
24
- # ' @returns The original \code{Experiment} object if provided. Otherwise,
24
+ # ' @returns The original \code{Experiment} object if provided. Otherwise,
25
25
# ' returns \code{NULL}.
26
26
# '
27
27
# ' @examples
28
28
# ' \dontrun{
29
29
# ' # create documentation template from an experiment (of class `Experiment`)
30
- # ' create_doc_template (experiment)
30
+ # ' init_docs (experiment)
31
31
# '
32
32
# ' # or alternatively, create documentation template from a specific directory
33
- # ' create_doc_template (save_dir = experiment$get_save_dir())}
33
+ # ' init_docs (save_dir = experiment$get_save_dir())}
34
34
# '
35
35
# ' @export
36
- create_doc_template <- function (experiment , save_dir ) {
36
+ init_docs <- function (experiment , save_dir ) {
37
37
if (missing(experiment ) && missing(save_dir )) {
38
38
stop(" Must provide argument for one of experiment or save_dir." )
39
39
}
@@ -45,16 +45,16 @@ create_doc_template <- function(experiment, save_dir) {
45
45
}
46
46
save_dir <- experiment $ get_save_dir()
47
47
}
48
-
48
+
49
49
if (! dir.exists(file.path(save_dir , " docs" ))) {
50
50
dir.create(file.path(save_dir , " docs" ), recursive = TRUE )
51
51
}
52
-
52
+
53
53
if (! file.exists(file.path(save_dir , " docs" , " objectives.md" ))) {
54
54
fname <- file.path(save_dir , " docs" , " objectives.md" )
55
55
utils :: write.csv(NULL , file = fname , quote = F )
56
56
}
57
-
57
+
58
58
descendants <- purrr :: map(
59
59
list.dirs(save_dir ), function (d ) {
60
60
if (file.exists(file.path(d , " experiment.rds" ))) {
@@ -65,7 +65,7 @@ create_doc_template <- function(experiment, save_dir) {
65
65
}
66
66
)
67
67
descendants [sapply(descendants , is.null )] <- NULL
68
-
68
+
69
69
fields <- c(" dgp" , " method" , " evaluator" , " visualizer" )
70
70
if (identical(descendants , list ()) && ! missing(experiment )) {
71
71
saveRDS(experiment , file.path(save_dir , " experiment.rds" ))
@@ -89,26 +89,41 @@ create_doc_template <- function(experiment, save_dir) {
89
89
}
90
90
}
91
91
}
92
-
92
+
93
93
if (! missing(experiment )) {
94
94
return (invisible (experiment ))
95
95
}
96
96
}
97
97
98
- # ' Create an R Markdown file summarizing the results of an \code{Experiment} or
98
+ # ' Initialize documentation template for the R Markdown results report.
99
+ # '
100
+ # ' @description
101
+ # ' `r lifecycle::badge("deprecated")`
102
+ # '
103
+ # ' `create_doc_template()` was renamed to `init_docs()` to create a more
104
+ # ' consistent API.
105
+ # '
106
+ # ' @keywords internal
107
+ # ' @export
108
+ create_doc_template <- function (experiment , save_dir ) {
109
+ lifecycle :: deprecate_warn(" 0.1.0" , " create_doc_template()" , " init_docs()" )
110
+ init_docs(experiment , save_dir )
111
+ }
112
+
113
+ # ' Render an R Markdown file summarizing the results of an \code{Experiment} or
99
114
# ' set of \code{Experiments}.
100
115
# '
101
- # ' @name create_rmd
116
+ # ' @name render_docs
102
117
# ' @description Knits an R Markdown file summarizing the results of an
103
- # ' \code{Experiment} or set of \code{Experiments}. Outputs an R
118
+ # ' \code{Experiment} or set of \code{Experiments}. Outputs an R
104
119
# ' Markdown-generated html file. If \code{experiment} is provided, the results
105
120
# ' are saved in the \code{Experiment}'s root results directory (see
106
121
# ' \code{Experiment$get_save_dir()}). Otherwise, the root results directory is
107
- # ' taken to be that specified by \code{save_dir}. Note that
108
- # ' \code{create_rmd ()} will process and include results from all
122
+ # ' taken to be that specified by \code{save_dir}. Note that
123
+ # ' \code{render_docs ()} will process and include results from all
109
124
# ' \code{Experiments} found *under* the root directory.
110
125
# '
111
- # ' @inheritParams create_doc_template
126
+ # ' @inheritParams init_docs
112
127
# ' @param open If \code{TRUE}, open the R Markdown-generated html file in a
113
128
# ' web browser.
114
129
# ' @param title Character string. Title of the report. By default, this will be
@@ -117,37 +132,37 @@ create_doc_template <- function(experiment, save_dir) {
117
132
# ' Markdown document.
118
133
# ' @param verbose Level of verboseness (0, 1, 2) when knitting R Markdown.
119
134
# ' Default is 2.
120
- # ' @param quiet Default is \code{TRUE}. See [rmarkdown::render()] for
135
+ # ' @param quiet Default is \code{TRUE}. See [rmarkdown::render()] for
121
136
# ' details.
122
137
# ' @param pretty Logical. Specifies whether or not to use pretty R Markdown
123
138
# ' results template or more barebones R Markdown results template. Default
124
139
# ' \code{TRUE} uses the pretty template. Set to \code{FALSE} to start from
125
140
# ' the barebones template, which can be helpful when using your own custom
126
141
# ' R Markdown theme.
127
- # ' @param eval_order Vector of \code{Evaluator} names in their desired order for
142
+ # ' @param eval_order Vector of \code{Evaluator} names in their desired order for
128
143
# ' display. By default, the report will display the \code{Evaluator} results
129
144
# ' in the order that they were computed.
130
- # ' @param viz_order Vector of \code{Visualizer} names in their desired order for
145
+ # ' @param viz_order Vector of \code{Visualizer} names in their desired order for
131
146
# ' display. By default, the report will display the \code{Visualizer} results
132
147
# ' in the order that they were computed.
133
148
# ' @param ... Additional arguments to pass to [rmarkdown::render()]. Useful
134
149
# ' for applying a custom R Markdown output theme.
135
150
# '
136
- # ' @returns The original \code{Experiment} object if provided. Otherwise,
151
+ # ' @returns The original \code{Experiment} object if provided. Otherwise,
137
152
# ' returns \code{NULL}.
138
153
# '
139
154
# ' @examples
140
155
# ' \dontrun{
141
156
# ' # create basic Rmd from an experiment (of class `Experiment`)
142
- # ' create_rmd (experiment)
157
+ # ' render_docs (experiment)
143
158
# '
144
159
# ' # or alternatively, create basic Rmd from a specific directory
145
- # ' create_rmd (save_dir = experiment$get_save_dir())}
160
+ # ' render_docs (save_dir = experiment$get_save_dir())}
146
161
# '
147
162
# ' @export
148
- create_rmd <- function (experiment , save_dir , open = TRUE , title = NULL ,
149
- author = " " , verbose = 2 , quiet = TRUE , pretty = TRUE ,
150
- eval_order = NULL , viz_order = NULL , ... ) {
163
+ render_docs <- function (experiment , save_dir , open = TRUE , title = NULL ,
164
+ author = " " , verbose = 2 , quiet = TRUE , pretty = TRUE ,
165
+ eval_order = NULL , viz_order = NULL , ... ) {
151
166
if (missing(experiment ) && missing(save_dir )) {
152
167
stop(" Must provide argument for one of experiment or save_dir." )
153
168
}
@@ -166,9 +181,9 @@ create_rmd <- function(experiment, save_dir, open = TRUE, title = NULL,
166
181
title <- " Results"
167
182
}
168
183
}
169
-
170
- create_doc_template (save_dir = save_dir )
171
-
184
+
185
+ init_docs (save_dir = save_dir )
186
+
172
187
if (pretty ) {
173
188
input_fname <- system.file(" rmd" , " results_pretty.Rmd" ,
174
189
package = utils :: packageName())
@@ -177,17 +192,36 @@ create_rmd <- function(experiment, save_dir, open = TRUE, title = NULL,
177
192
package = utils :: packageName())
178
193
}
179
194
output_fname <- file.path(save_dir , paste0(title , " .html" ))
180
- params_list <- list (sim_name = title , sim_path = save_dir , author = author ,
181
- eval_order = eval_order , viz_order = viz_order ,
195
+ params_list <- list (sim_name = title , sim_path = save_dir , author = author ,
196
+ eval_order = eval_order , viz_order = viz_order ,
182
197
verbose = verbose )
183
198
rmarkdown :: render(input = input_fname , params = params_list ,
184
199
output_file = output_fname , quiet = quiet , ... )
185
200
output_fname <- stringr :: str_replace_all(output_fname , " " , " \\\\ " )
186
201
if (open ) {
187
202
system(paste(" open" , output_fname ))
188
203
}
189
-
204
+
190
205
if (! missing(experiment )) {
191
206
return (invisible (experiment ))
192
207
}
193
- }
208
+ }
209
+
210
+ # ' Render an R Markdown file summarizing the results of an \code{Experiment} or
211
+ # ' set of \code{Experiments}.
212
+ # '
213
+ # ' @description
214
+ # ' `r lifecycle::badge("deprecated")`
215
+ # '
216
+ # ' `create_rmd()` was renamed to `render_docs()` to create a more consistent
217
+ # ' API.
218
+ # '
219
+ # ' @keywords internal
220
+ # ' @export
221
+ create_rmd <- function (experiment , save_dir , open = TRUE , title = NULL ,
222
+ author = " " , verbose = 2 , quiet = TRUE , pretty = TRUE ,
223
+ eval_order = NULL , viz_order = NULL , ... ) {
224
+ lifecycle :: deprecate_warn(" 0.1.0" , " create_rmd()" , " render_docs()" )
225
+ render_docs(experiment , save_dir , open , title , author , verbose , quiet ,
226
+ pretty , eval_order , viz_order , ... )
227
+ }
0 commit comments