New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
diff functions #404
diff functions #404
Conversation
R/compare_designs.R
Outdated
set.seed(seed) | ||
design1 <- draw_data(design1) | ||
set.seed(seed) | ||
design2 <- draw_data(design2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One cute thing would be if the ending .Random.seed was the same after two draws - if not, then you know the designs had different access patterns to the RNG.
R/compare_designs.R
Outdated
#' @rdname compare_functions | ||
#' @importFrom diffobj diffChr | ||
#' @export | ||
compare_design_summaries <- function(design1, design2, format = "ansi256", mode = "sidebyside", pager = "off", context = -1L) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this family of functions, parameterize by the comparison function:
compare_design_generic <- function(FUN, design1, design2, format = "ansi256", ...){
seed <- .Random.seed
x <- FUN(design1)
set.seed(seed)
y <- FUN(design2)
#etc
}
compare_design_summaries <- stackoverflow::partial(compare_design_generic, FUN=function(x) capture.output(summary(x)))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also parameterize DIFF_FUN
.
R/compare_designs.R
Outdated
} | ||
|
||
get_design_code <- function(design){ | ||
sapply(design, function(x) clean_call(attributes(x)$call)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attr(x, "call")
R/compare_designs.R
Outdated
print.design_comparison <- function(x, ...) { | ||
cat("Research design comparison\n\n") | ||
|
||
print_console_header("Compare design code") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use a list, eg
labels = c("code_comparison"="design code", "data_comparison" = "draw_data(design)")
for(n in names(labels)) {
print_console_header(paste("Compare", labels[n))
print(x[[n]])
}
R/compare_designs.R
Outdated
|
||
estimands_comparison <- compare_design_estimands(design1, design2, format = format, mode = mode, pager = pager, context = context) | ||
|
||
estimates_comparison <- compare_design_estimates(design1, design2, format = format, mode = mode, pager = pager, context = context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eek. Use a list to cut down on verbosity.
fns <- list(code_comparison=compare_design_code, data_comparison=compare_design_data, ...)
vals <- lappy(fns, function(f) f(design1, design2, format=format, mode=mode, pager=pager, context=context)
class(vals) <- "design_comparison"
vals
compare_design_code
which does diff of codecompare_design_estimates
which runs draw_estimates(design) and then does a diff of the outputcompare_design_estimands
which runs draw_estimands(design) and then does a diff of the outputcompare_design_data
which runs draw_data(design) and then does a diff of the outputcompare_design_summaries
which runs summary(design) and then does a diff of the outputand an omnibus function that runs them all one by one with section headers in between -
compare_designs