diff --git a/NAMESPACE b/NAMESPACE index 4af6d37..51e95f5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -18,6 +18,12 @@ S3method(examine_recipe,edbl_table) S3method(examine_recipe,takeout) S3method(format,edbl_fct) S3method(format,edbl_lvls) +S3method(graph_input,cond_lvls) +S3method(graph_input,cross_lvls) +S3method(graph_input,default) +S3method(graph_input,edbl_lvls) +S3method(graph_input,formula) +S3method(graph_input,nest_lvls) S3method(levels,edbl_fct) S3method(levels,edbl_lvls) S3method(names,edbl_design) @@ -132,6 +138,7 @@ export(fct_edges) export(fct_generator) export(fct_graph) export(fct_nodes) +export(graph_input) export(index_levels) export(is_cross_levels) export(is_edibble) diff --git a/R/graph-input.R b/R/graph-input.R index dfcec19..f3a4912 100644 --- a/R/graph-input.R +++ b/R/graph-input.R @@ -4,7 +4,7 @@ #' @param input An input. #' @param prov A provenance object. #' @param ... Unused. -#' @keywords internal +#' @export graph_input <- function(input, prov, ...) { UseMethod("graph_input") } @@ -18,6 +18,7 @@ graph_input_type = function(input) { return("unimplemented") } +#' @export graph_input.default <- function(input, prov, name, class, ...) { type <- graph_input_type(input) levels <- switch(type, @@ -29,6 +30,7 @@ graph_input.default <- function(input, prov, name, class, ...) { graph_input.edbl_lvls(levels, prov, name, class) } +#' @export graph_input.edbl_lvls <- function(input, prov, name, class, ...) { fattrs <- as.data.frame(attr(input, "attrs")) prov$append_fct_nodes(name = name, role = class, attrs = fattrs) @@ -39,12 +41,14 @@ graph_input.edbl_lvls <- function(input, prov, name, class, ...) { prov$append_lvl_nodes(value = value, n = n, fid = prov$fct_id(name = name), attrs = lattrs) } +#' @export graph_input.formula <- function(input, prov, name, class, ...) { tt <- stats::terms(input) vars <- rownames(attr(tt, "factors")) graph_input.cross_lvls(vars, prov, name, class) } +#' @export graph_input.cross_lvls <- function(input, prov, name, class, ...) { flevels <- prov$fct_levels(return = "value") vars <- input @@ -66,6 +70,7 @@ graph_input.cross_lvls <- function(input, prov, name, class, ...) { } } +#' @export graph_input.nest_lvls <- function(input, prov, name, class, ...) { parent <- input %@% "keyname" cross_parents <- input %@% "parents" @@ -94,7 +99,7 @@ graph_input.nest_lvls <- function(input, prov, name, class, ...) { } - +#' @export graph_input.cond_lvls <- function(input, prov, name, class, ...) { parent <- input %@% "keyname" cross_parents <- input %@% "parents" diff --git a/R/simulate.R b/R/simulate.R index 188dddc..e839617 100644 --- a/R/simulate.R +++ b/R/simulate.R @@ -475,14 +475,14 @@ effects_code <- function(dep_fcts, .data, nlevels = 1) { sprintf('%s_degree <- sample(1:%d, 1)', fct, ifelse(nfct > 5, 5, nfct - 1)), paste(sprintf('%s_effects <- as.vector(poly(%s, %s_degree)', fct, fct, fct), "%*%", - sprintf('rnorm(%s_degree, 0, %.1f))', fct, runif(1, 1, 10)))) + sprintf('rnorm(%s_degree, 0, %.1f))', fct, stats::runif(1, 1, 10)))) code_list$model_code <- c(code_list$model_code, sprintf("%s_effects", fct)) # logical not accounted for } else if(any(c("factor", "character") %in% fct_class)) { code_list$process_code <- c(code_list$process_code, sprintf(' %s_effects <- rnorm(%d, 0, %.1f)', - fct, nfct, runif(1, 1, 10))) + fct, nfct, stats::runif(1, 1, 10))) code_list$model_code <- c(code_list$model_code, sprintf("%s_effects[index_levels(%s)]", fct, fct)) } } @@ -495,13 +495,13 @@ effects_code <- function(dep_fcts, .data, nlevels = 1) { if("numeric" %in% fct_class) { code_list$process_code <- c(code_list$process_code, sprintf(' %s_degree <- lapply(1:%d, function(i) sample(1:%d, 1))', fct, nlevels, nfct), - sprintf(' %s_effects <- lapply(1:%d, function(i) as.vector(poly(%s, %s_degree[[i]]) %*% rnorm(%s_degree[[i]], 0, %.1f)))', fct, nlevels, fct, fct, fct, runif(1, 1, 10))) + sprintf(' %s_effects <- lapply(1:%d, function(i) as.vector(poly(%s, %s_degree[[i]]) %*% rnorm(%s_degree[[i]], 0, %.1f)))', fct, nlevels, fct, fct, fct, stats::runif(1, 1, 10))) code_list$model_code <- c(code_list$model_code, sprintf("%s_effects[[i]]", fct)) } else if(any(c("factor", "character") %in% fct_class)) { code_list$process_code <- c(code_list$process_code, sprintf(' %s_effects <- lapply(1:%d, function(i) rnorm(%d, 0, %.1f))', - fct, nlevels, nfct, runif(1, 1, 10))) + fct, nlevels, nfct, stats::runif(1, 1, 10))) code_list$model_code <- c(code_list$model_code, sprintf("%s_effects[[i]][index_levels(%s)]", fct, fct)) } } diff --git a/README.md b/README.md index 5b8e9a0..bcfbbba 100644 --- a/README.md +++ b/README.md @@ -65,16 +65,16 @@ serve_table(des) #> class student style exam #> #> -#> 1 class1 student001 traditional take-home -#> 2 class1 student002 traditional take-home -#> 3 class1 student003 traditional take-home -#> 4 class1 student004 traditional open-book +#> 1 class1 student001 traditional take-home +#> 2 class1 student002 traditional take-home +#> 3 class1 student003 traditional take-home +#> 4 class1 student004 traditional open-book #> 5 class1 student005 traditional closed-book #> 6 class1 student006 traditional closed-book #> 7 class1 student007 traditional closed-book -#> 8 class1 student008 traditional open-book -#> 9 class1 student009 traditional open-book -#> 10 class1 student010 traditional open-book +#> 8 class1 student008 traditional open-book +#> 9 class1 student009 traditional open-book +#> 10 class1 student010 traditional open-book #> # ℹ 110 more rows ``` diff --git a/cran-comments.md b/cran-comments.md index 152bb50..092e518 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,29 +1,17 @@ ## Release summary -This update makes a number of bug fixes, addition of new features and -quality of life improvements as shown below. +This update makes fix a couple of bugs and small improvements as shown below. Bug fixes -* Bug fix for export_design when no record factor exists -* Bug fix for order assignment +* Factor inputs were displayed integers. Fixed so this does not happen. +* S3 methods are exported. -Quality of life improvements +Improvements -* Format change for the title page in the export -* Change behaviour of `fct_attrs()` when levels supplied as numeric or vector - instead of `lvls()`. -* Change the print out of edibble table. -* Improve the assignment algorithm. +* If an edibble object is created from existing data, level edges are added when using `allot_trts()`. +* If a record factor is specified from existing data, the unit levels are added as attributes. -New features - -* Added new functions `count_by()` and `split_by()`. -* Added ability to specify conditional treatment. -* The `simuluate_rcrds()` has now a facelift with delineation of the process specification to `simulate_process()`. -* `autofill_rcrds()` implemented. -* Added ability to add two designs by `+`. -* Ability to add metadata through design(). ## R CMD check results diff --git a/man/graph_input.Rd b/man/graph_input.Rd index 2c9fc32..b8a1474 100644 --- a/man/graph_input.Rd +++ b/man/graph_input.Rd @@ -16,4 +16,3 @@ graph_input(input, prov, ...) \description{ A function to process input as input for graph manipulation } -\keyword{internal} diff --git a/tests/testthat/_snaps/rcrds.md b/tests/testthat/_snaps/rcrds.md index eebd54f..a3720f5 100644 --- a/tests/testthat/_snaps/rcrds.md +++ b/tests/testthat/_snaps/rcrds.md @@ -8,16 +8,16 @@ class student style exam exam_mark room - 1 class1 student001 flipped take-home o o - 2 class1 student002 flipped take-home o x - 3 class1 student003 flipped closed-book o x - 4 class1 student004 flipped take-home o x - 5 class1 student005 flipped take-home o x - 6 class1 student006 flipped take-home o x - 7 class1 student007 flipped open-book o x - 8 class1 student008 flipped open-book o x - 9 class1 student009 flipped take-home o x - 10 class1 student010 flipped closed-book o x + 1 class1 student001 flipped closed-book o o + 2 class1 student002 flipped take-home o x + 3 class1 student003 flipped open-book o x + 4 class1 student004 flipped closed-book o x + 5 class1 student005 flipped closed-book o x + 6 class1 student006 flipped open-book o x + 7 class1 student007 flipped closed-book o x + 8 class1 student008 flipped open-book o x + 9 class1 student009 flipped take-home o x + 10 class1 student010 flipped take-home o x # i 110 more rows --- @@ -44,16 +44,16 @@ class student style exam exam_mark room - 1 class1 student001 flipped take-home o o - 2 class1 student002 flipped take-home o x - 3 class1 student003 flipped closed-book o x - 4 class1 student004 flipped take-home o x - 5 class1 student005 flipped take-home o x - 6 class1 student006 flipped take-home o x - 7 class1 student007 flipped open-book o x - 8 class1 student008 flipped open-book o x - 9 class1 student009 flipped take-home o x - 10 class1 student010 flipped closed-book o x + 1 class1 student001 flipped closed-book o o + 2 class1 student002 flipped take-home o x + 3 class1 student003 flipped open-book o x + 4 class1 student004 flipped closed-book o x + 5 class1 student005 flipped closed-book o x + 6 class1 student006 flipped open-book o x + 7 class1 student007 flipped closed-book o x + 8 class1 student008 flipped open-book o x + 9 class1 student009 flipped take-home o x + 10 class1 student010 flipped take-home o x # i 110 more rows --- @@ -83,16 +83,16 @@ class student style exam exam_mark quiz1_mark quiz2_mark gender - 1 class1 student001 flipped take-home~ o o o o - 2 class1 student002 flipped take-home~ o o o o - 3 class1 student003 flipped closed-bo~ o o o o - 4 class1 student004 flipped take-home~ o o o o - 5 class1 student005 flipped take-home~ o o o o - 6 class1 student006 flipped take-home~ o o o o - 7 class1 student007 flipped open-book~ o o o o - 8 class1 student008 flipped open-book~ o o o o - 9 class1 student009 flipped take-home~ o o o o - 10 class1 student010 flipped closed-bo~ o o o o + 1 class1 student001 flipped closed-bo~ o o o o + 2 class1 student002 flipped take-home o o o o + 3 class1 student003 flipped open-book o o o o + 4 class1 student004 flipped closed-bo~ o o o o + 5 class1 student005 flipped closed-bo~ o o o o + 6 class1 student006 flipped open-book o o o o + 7 class1 student007 flipped closed-bo~ o o o o + 8 class1 student008 flipped open-book o o o o + 9 class1 student009 flipped take-home o o o o + 10 class1 student010 flipped take-home o o o o # i 110 more rows # i 2 more variables: room , teacher diff --git a/tests/testthat/_snaps/trts.md b/tests/testthat/_snaps/trts.md index 7c933d3..8b42652 100644 --- a/tests/testthat/_snaps/trts.md +++ b/tests/testthat/_snaps/trts.md @@ -444,22 +444,22 @@ irr1 irr2 - fert1 0 2 - fert2 0 2 + fert1 0 0 + fert2 0 4 , , = wplot02 irr1 irr2 - fert1 2 0 - fert2 2 0 + fert1 0 3 + fert2 0 1 , , = wplot03 irr1 irr2 - fert1 0 2 - fert2 0 2 + fert1 0 3 + fert2 0 1 , , = wplot04 @@ -472,50 +472,50 @@ irr1 irr2 - fert1 0 2 - fert2 0 2 + fert1 0 4 + fert2 0 0 , , = wplot06 irr1 irr2 - fert1 2 0 - fert2 2 0 + fert1 0 1 + fert2 0 3 , , = wplot07 irr1 irr2 - fert1 2 0 - fert2 2 0 + fert1 3 0 + fert2 1 0 , , = wplot08 irr1 irr2 - fert1 2 0 - fert2 2 0 + fert1 3 0 + fert2 1 0 , , = wplot09 irr1 irr2 - fert1 0 2 - fert2 0 2 + fert1 2 0 + fert2 2 0 , , = wplot10 irr1 irr2 - fert1 2 0 - fert2 2 0 + fert1 1 0 + fert2 3 0 , , = wplot11 irr1 irr2 - fert1 0 2 - fert2 0 2 + fert1 0 3 + fert2 0 1 , , = wplot12 @@ -528,85 +528,85 @@ irr1 irr2 - fert1 2 0 - fert2 2 0 + fert1 0 2 + fert2 0 2 , , = wplot14 irr1 irr2 - fert1 0 2 - fert2 0 2 + fert1 3 0 + fert2 1 0 , , = wplot15 irr1 irr2 - fert1 2 0 - fert2 2 0 + fert1 1 0 + fert2 3 0 , , = wplot16 irr1 irr2 - fert1 0 2 - fert2 0 2 + fert1 0 4 + fert2 0 0 , , = wplot17 irr1 irr2 - fert1 2 0 - fert2 2 0 + fert1 1 0 + fert2 3 0 , , = wplot18 irr1 irr2 - fert1 0 2 - fert2 0 2 + fert1 0 3 + fert2 0 1 , , = wplot19 irr1 irr2 - fert1 2 0 - fert2 2 0 + fert1 0 1 + fert2 0 3 , , = wplot20 irr1 irr2 - fert1 0 2 - fert2 0 2 + fert1 3 0 + fert2 1 0 , , = wplot21 irr1 irr2 - fert1 0 2 - fert2 0 2 + fert1 1 0 + fert2 3 0 , , = wplot22 irr1 irr2 - fert1 0 2 - fert2 0 2 + fert1 0 3 + fert2 0 1 , , = wplot23 irr1 irr2 - fert1 2 0 - fert2 2 0 + fert1 0 0 + fert2 4 0 , , = wplot24 irr1 irr2 - fert1 2 0 - fert2 2 0 + fert1 1 0 + fert2 3 0 , , = wplot25 @@ -619,35 +619,35 @@ irr1 irr2 - fert1 0 2 - fert2 0 2 + fert1 0 0 + fert2 4 0 , , = wplot27 irr1 irr2 - fert1 2 0 - fert2 2 0 + fert1 1 0 + fert2 3 0 , , = wplot28 irr1 irr2 - fert1 2 0 - fert2 2 0 + fert1 0 1 + fert2 0 3 , , = wplot29 irr1 irr2 - fert1 2 0 - fert2 2 0 + fert1 0 3 + fert2 0 1 , , = wplot30 irr1 irr2 - fert1 0 2 - fert2 0 2 + fert1 3 0 + fert2 1 0