For testing purposes in the summarize_simulations2.R function. Stops the process if different parameters are specified from the ones the script is built to analyze.
For the purposes of testing the error inside summarize_simulations2, this markdown script provides function "summarize_simulation_error", a truncated version of summarize_simulations which takes in a single dataset instead of all the parameters.
The expected output from this "error" function is a table with 6 parameters (15 ct estimates for 4 parameters, and 2 estimates for 2 global parameters) and their point estimates and uncertainty intervals if given "workingtib" (drawn from mcmctib_n) and a stop error if given "errortib" (generated with 4 variables.)
#Load the data & source the function library(tidyverse) library(testthat) errortib <- readRDS(paste(getwd(), '/test', 'errortib.RDS')) workingtib <- readRDS(paste(getwd(), '/test', 'workingtib.RDS'))
summarize_simulation_error <- function(data) { # tib <- # readRDS(paste(output.dir, '/mcmctib_', simnum, '.RDS', sep = "")) tidydat <- data %>% select( contains("sens"), contains("spec"), contains("vradj.ct"), contains("gamma.truematvr.ct") ) if (ncol(tidydat) < 62) { #for testing purposes #only and all selected parameter should be in this set stop( paste0( "At least oneparameter of interest is missing. .\n", "Check to make sure mcmctib_ is correct" ) ) call. = FALSE } # else { # tidydat <- tidydat %>% # gather(key = "parameter", value = "value") %>% # group_by(parameter) %>% # summarize( # lower = quantile(value, .025), # median = quantile(value, .5), # upper = quantile(value, .975) # ) %>% # #print() # } }
expect_error(summarize_simulation_error(errortib)) expect_silent(summarize_simulation_error(workingtib)) test_that("function gives error when the data is missing parameters", { expect_error(summarize_simulation_error(errortib)) expect_silent(summarize_simulation_error(workingtib)) })
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.