hadley/test_that — Issue #24: convenience function for expect_that
Author: Scott-Kostyshak
Created: 2011-10-25 02:32:13+00:00
State: open

The following is a convenience test that is useful when you are working in an interactive session and you decide that you want
to test one of the objects in your workspace. The function inputs the object you want to test and an argument that must be "equals", "is_equivalent_to", or "is_identical_to". It outputs the test that you can copy and paste into an R script.

export_test <- function(x, test = "equals") {
stopifnot(test %in% c("equals","is_equivalent_to","is_identical_to"))
substitute(expect_that(subme1,subme2(subme3)),list(subme1=substitute(x),subme2=as.name(test),subme3=x))
}

For example, suppose you have the following factor:
happiness <- factor(c("happy", "not at all happy", "not at all happy", "quite happy", "not very happy"))
If you run the following command,
export_test(levels(happiness),"is_identical_to")
You get this output:
expect_that(levels(happiness), is_identical_to(c("happy", "not at all happy", "not very happy", "quite happy")))