Skip to content

Commit

Permalink
add ability to add metadata for experiment through design()
Browse files Browse the repository at this point in the history
  • Loading branch information
emitanaka committed Oct 15, 2023
1 parent 9fb8a0e commit a3783a1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 35 deletions.
35 changes: 20 additions & 15 deletions R/design.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
#' @description
#' This function doesn't really do much besides create a new edibble design object.
#'
#' @param title Optional title of the experiment.
#' @param name Optional name of the experiment.
#' @param .title Optional title of the experiment.
#' @param ... A series of name-value pairs where the name corresponds to the
#' name of the metadata nad the value corresponds to the actual metadata value.
#' If the name is omitted, then no name to the metadata is assigned for the
#' corresponding value.
#' @param .name Optional name of the experiment.
#' @inheritParams set_units
#' @param seed A seed number for reproducibility.
#' @param .seed A seed number for reproducibility.
#' @param .data An edibble table.
#' @param provenance An environment setup in a manner to store methods and
#' @param .provenance An environment setup in a manner to store methods and
#' information to trace the origin of the design
#' @return An empty `edbl_design` object.
#' @examples
Expand All @@ -17,27 +21,28 @@
#' [set_rcrds()].
#' @family user-facing functions
#' @export
design <- function(title = NULL, name = "edibble", .record = TRUE, seed = NULL, provenance = Provenance$new()) {
if(.record) provenance$record_step()
if(!is.null(title)) provenance$set_title(title)
provenance$set_name(name)
provenance$save_seed(seed, type = "design")
structure(list(graph = provenance$get_graph(),
design <- function(.title = NULL, ..., .name = "edibble", .record = TRUE, .seed = NULL, .provenance = Provenance$new()) {
if(.record) .provenance$record_step()
if(!is.null(.title)) .provenance$set_title(.title)
.provenance$set_name(.name)
.provenance$save_seed(.seed, type = "design")
context <- dots_list(..., .ignore_empty = "trailing")
structure(list(graph = .provenance$get_graph(),
validation = list(rcrds = NULL),
provenance = provenance,
provenance = .provenance,
anatomy = NULL,
recipe = NULL,
simulate = list(),
simulate_result = list(),
context = NULL),
context = context),
class = c("edbl_design", "edbl"))
}

#' @rdname design
#' @export
redesign <- function(.data, name = NULL, .record = TRUE, seed = NULL, provenance = provenance, ...) {
des <- design(name = name, .record = .record, seed = seed, provenance = provenance)
new_edibble(.data, ..., design = des)
redesign <- function(.data, .title, ..., .name = NULL, .record = TRUE, .seed = NULL, .provenance = Provenance$new()) {
des <- design(.title = .title, ..., .name = .name, .record = .record, .seed = .seed, .provenance = .provenance)
new_edibble(.data, design = des)
}

# initialise graph structure -----------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions R/edibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ as_edibble <- function(.data, ...) {
}

#' @export
as_edibble.data.frame <- function(.data, title = NULL, name = "edibble", .record = TRUE, seed = NULL, provenance = Provenance$new(), units = NULL, trts = NULL, ...) {
if(.record) provenance$record_step()
des <- design(title = title, name = name, .record = FALSE, seed = seed, provenance = provenance)
new_edibble(.data, ..., .design = des) %>%
set_units({{units}}) %>%
set_trts({{trts}})
as_edibble.data.frame <- function(.data, .title = NULL, ..., .name = "edibble", .record = TRUE, .seed = NULL, .provenance = Provenance$new(), .units = NULL, .trts = NULL) {
if(.record) .provenance$record_step()
des <- design(.title = .title, ..., .name = .name, .record = FALSE, .seed = .seed, .provenance = .provenance)
new_edibble(.data, .design = des) %>%
set_units({{.units}}) %>%
set_trts({{.trts}})
}

# idk what's the point of this function
Expand Down
33 changes: 19 additions & 14 deletions man/design.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a3783a1

Please sign in to comment.