diff --git a/NAMESPACE b/NAMESPACE index b0088a5..c0c05ef 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -36,6 +36,7 @@ S3method(print,recipe_design) S3method(print,sim_process) S3method(print,split_by) S3method(print,takeout) +S3method(rbind,edbl_table) S3method(tbl_sum,edbl_table) S3method(tbl_sum,trck_table) S3method(type_sum,edbl_fct) diff --git a/R/simulate.R b/R/simulate.R index 77cc519..5d7e26a 100644 --- a/R/simulate.R +++ b/R/simulate.R @@ -124,7 +124,7 @@ with_params <- function(..., .censor = NA, .aggregate = NULL) { #' simulate_process(y = function() { #' res <- rnorm(n()) #' res -#'. }) %>% +#' }) %>% #' simulate_rcrds(y = with_params(), .nsim = 3) #' #' @@ -238,7 +238,7 @@ get_censored_value <- function(y, valid, censor) { } else if(type=="integer") { valid$record <- "numeric" res <- get_censored_value(y, valid, censor) - round(res) + as.integer(round(res)) } else { y } @@ -344,8 +344,9 @@ with_variables <- function(..., #' @param ... If supplied, it is a name-value pair where the name should #' correspond to the record factor name and value is the f #' @param .seed The seed number. +#' @param .nsim The number of simulations to run. #' @export -autofill_rcrds <- function(.data, ..., .seed = NULL) { +autofill_rcrds <- function(.data, ..., .seed = NULL, .nsim = 1L) { prov <- activate_provenance(.data) prov$save_seed(.seed, type = "autofill_rcrds") dots <- list2(...) @@ -456,7 +457,8 @@ autofill_rcrds <- function(.data, ..., .seed = NULL) { simulate_processes <- sprintf("simulate_process(%s)", paste(process_functions, collapse = ",\n")) - simulate_rcrds <- paste0('simulate_rcrds(', paste0(processes, collapse = ',\n '), ')') + simulate_rcrds <- paste0('simulate_rcrds(', paste0(processes, collapse = ',\n '), + ', .nsim = ', .nsim, ')') final_code <- parse(text = paste(".data %>%\n ", simulate_processes, "%>%\n ", simulate_rcrds)) eval(final_code) } diff --git a/R/utils.R b/R/utils.R index 37d16f8..83cb453 100644 --- a/R/utils.R +++ b/R/utils.R @@ -473,4 +473,7 @@ print.edbl_fct <- function(x, ...) { } } - +#' @export +rbind.edbl_table <- function(...) { + dplyr::bind_rows(...) +} diff --git a/man/autofill_rcrds.Rd b/man/autofill_rcrds.Rd index c5311e8..c9445bc 100644 --- a/man/autofill_rcrds.Rd +++ b/man/autofill_rcrds.Rd @@ -4,7 +4,7 @@ \alias{autofill_rcrds} \title{Autofill the records} \usage{ -autofill_rcrds(.data, ..., .seed = NULL) +autofill_rcrds(.data, ..., .seed = NULL, .nsim = 1L) } \arguments{ \item{.data}{An edibble data.} @@ -13,6 +13,8 @@ autofill_rcrds(.data, ..., .seed = NULL) correspond to the record factor name and value is the f} \item{.seed}{The seed number.} + +\item{.nsim}{The number of simulations to run.} } \description{ This function fills the values of the record factors by automatically diff --git a/man/simulate_rcrds.Rd b/man/simulate_rcrds.Rd index 3f60122..dc7b9d3 100644 --- a/man/simulate_rcrds.Rd +++ b/man/simulate_rcrds.Rd @@ -29,7 +29,7 @@ design() \%>\% simulate_process(y = function() { res <- rnorm(n()) res -. }) \%>\% + }) \%>\% simulate_rcrds(y = with_params(), .nsim = 3)