Skip to content

Commit b5e328a

Browse files
authored
Merge pull request #126 from Yu-Group/fix-tests
Fix tests, allow multi vary across, rename `rmd` functions to `docs`
2 parents 75baada + d4905ad commit b5e328a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1896
-1543
lines changed

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Imports:
2424
fontawesome,
2525
future,
2626
future.apply,
27+
lifecycle,
2728
magrittr,
2829
methods,
2930
purrr,
@@ -65,10 +66,10 @@ Remotes:
6566
Config/testthat/edition: 3
6667
Encoding: UTF-8
6768
Roxygen: list(markdown = TRUE, r6 = FALSE)
68-
RoxygenNote: 7.2.0
69+
RoxygenNote: 7.2.2
6970
Collate:
70-
'create_rmd.R'
7171
'dgp.R'
72+
'docs.R'
7273
'evaluator-lib-feature-selection.R'
7374
'evaluator-lib-inference.R'
7475
'evaluator-lib-prediction.R'

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export(get_methods)
4545
export(get_save_dir)
4646
export(get_vary_across)
4747
export(get_visualizers)
48+
export(init_docs)
4849
export(list_col_to_chr)
4950
export(neg)
5051
export(neg_vec)
@@ -65,8 +66,10 @@ export(remove_evaluator)
6566
export(remove_method)
6667
export(remove_vary_across)
6768
export(remove_visualizer)
69+
export(render_docs)
6870
export(run_experiment)
6971
export(save_experiment)
72+
export(set_doc_options)
7073
export(set_rmd_options)
7174
export(set_save_dir)
7275
export(summarize_eval_results)

R/create_rmd.R renamed to R/docs.R

Lines changed: 77 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
#' Create documentation template for the R Markdown results report.
1+
#' Initialize documentation template for the R Markdown results report.
22
#'
3-
#' @name create_doc_template
3+
#' @name init_docs
44
#' @description Create documentation template (a series of .md files) to
55
#' 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
99
#' \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
1212
#' \code{Experiment}.
1313
#'
1414
#' @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.
2020
#' @param save_dir An optional directory in which to find previously saved
2121
#' \code{Experiment} objects. Documentation is created for these found
2222
#' \code{Experiments}. Not used if \code{experiment} is provided.
2323
#'
24-
#' @returns The original \code{Experiment} object if provided. Otherwise,
24+
#' @returns The original \code{Experiment} object if provided. Otherwise,
2525
#' returns \code{NULL}.
2626
#'
2727
#' @examples
2828
#' \dontrun{
2929
#' # create documentation template from an experiment (of class `Experiment`)
30-
#' create_doc_template(experiment)
30+
#' init_docs(experiment)
3131
#'
3232
#' # 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())}
3434
#'
3535
#' @export
36-
create_doc_template <- function(experiment, save_dir) {
36+
init_docs <- function(experiment, save_dir) {
3737
if (missing(experiment) && missing(save_dir)) {
3838
stop("Must provide argument for one of experiment or save_dir.")
3939
}
@@ -45,16 +45,16 @@ create_doc_template <- function(experiment, save_dir) {
4545
}
4646
save_dir <- experiment$get_save_dir()
4747
}
48-
48+
4949
if (!dir.exists(file.path(save_dir, "docs"))) {
5050
dir.create(file.path(save_dir, "docs"), recursive = TRUE)
5151
}
52-
52+
5353
if (!file.exists(file.path(save_dir, "docs", "objectives.md"))) {
5454
fname <- file.path(save_dir, "docs", "objectives.md")
5555
utils::write.csv(NULL, file = fname, quote = F)
5656
}
57-
57+
5858
descendants <- purrr::map(
5959
list.dirs(save_dir), function(d) {
6060
if (file.exists(file.path(d, "experiment.rds"))) {
@@ -65,7 +65,7 @@ create_doc_template <- function(experiment, save_dir) {
6565
}
6666
)
6767
descendants[sapply(descendants, is.null)] <- NULL
68-
68+
6969
fields <- c("dgp", "method", "evaluator", "visualizer")
7070
if (identical(descendants, list()) && !missing(experiment)) {
7171
saveRDS(experiment, file.path(save_dir, "experiment.rds"))
@@ -89,26 +89,41 @@ create_doc_template <- function(experiment, save_dir) {
8989
}
9090
}
9191
}
92-
92+
9393
if (!missing(experiment)) {
9494
return(invisible(experiment))
9595
}
9696
}
9797

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
99114
#' set of \code{Experiments}.
100115
#'
101-
#' @name create_rmd
116+
#' @name render_docs
102117
#' @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
104119
#' Markdown-generated html file. If \code{experiment} is provided, the results
105120
#' are saved in the \code{Experiment}'s root results directory (see
106121
#' \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
109124
#' \code{Experiments} found *under* the root directory.
110125
#'
111-
#' @inheritParams create_doc_template
126+
#' @inheritParams init_docs
112127
#' @param open If \code{TRUE}, open the R Markdown-generated html file in a
113128
#' web browser.
114129
#' @param title Character string. Title of the report. By default, this will be
@@ -117,37 +132,37 @@ create_doc_template <- function(experiment, save_dir) {
117132
#' Markdown document.
118133
#' @param verbose Level of verboseness (0, 1, 2) when knitting R Markdown.
119134
#' 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
121136
#' details.
122137
#' @param pretty Logical. Specifies whether or not to use pretty R Markdown
123138
#' results template or more barebones R Markdown results template. Default
124139
#' \code{TRUE} uses the pretty template. Set to \code{FALSE} to start from
125140
#' the barebones template, which can be helpful when using your own custom
126141
#' 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
128143
#' display. By default, the report will display the \code{Evaluator} results
129144
#' 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
131146
#' display. By default, the report will display the \code{Visualizer} results
132147
#' in the order that they were computed.
133148
#' @param ... Additional arguments to pass to [rmarkdown::render()]. Useful
134149
#' for applying a custom R Markdown output theme.
135150
#'
136-
#' @returns The original \code{Experiment} object if provided. Otherwise,
151+
#' @returns The original \code{Experiment} object if provided. Otherwise,
137152
#' returns \code{NULL}.
138153
#'
139154
#' @examples
140155
#' \dontrun{
141156
#' # create basic Rmd from an experiment (of class `Experiment`)
142-
#' create_rmd(experiment)
157+
#' render_docs(experiment)
143158
#'
144159
#' # 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())}
146161
#'
147162
#' @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, ...) {
151166
if (missing(experiment) && missing(save_dir)) {
152167
stop("Must provide argument for one of experiment or save_dir.")
153168
}
@@ -166,9 +181,9 @@ create_rmd <- function(experiment, save_dir, open = TRUE, title = NULL,
166181
title <- "Results"
167182
}
168183
}
169-
170-
create_doc_template(save_dir = save_dir)
171-
184+
185+
init_docs(save_dir = save_dir)
186+
172187
if (pretty) {
173188
input_fname <- system.file("rmd", "results_pretty.Rmd",
174189
package = utils::packageName())
@@ -177,17 +192,36 @@ create_rmd <- function(experiment, save_dir, open = TRUE, title = NULL,
177192
package = utils::packageName())
178193
}
179194
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,
182197
verbose = verbose)
183198
rmarkdown::render(input = input_fname, params = params_list,
184199
output_file = output_fname, quiet = quiet, ...)
185200
output_fname <- stringr::str_replace_all(output_fname, " ", "\\\\ ")
186201
if (open) {
187202
system(paste("open", output_fname))
188203
}
189-
204+
190205
if (!missing(experiment)) {
191206
return(invisible(experiment))
192207
}
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

Comments
 (0)