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

convenience function for expect_that #24

scottkosty opened this Issue Oct 25, 2011 · 1 comment


None yet
3 participants

scottkosty commented Oct 25, 2011

The following is a convenience function 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"))

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,


You get this output:

expect_that(levels(happiness), is_identical_to(c("happy", "not at all happy", "not very happy", "quite happy")))

@scottkosty scottkosty closed this Oct 26, 2011

@scottkosty scottkosty reopened this Oct 26, 2011


This comment has been minimized.

floybix commented Jan 4, 2012

R has a built-in convenience function for this sort of thing:


@hadley hadley closed this in 42aabad Feb 28, 2012

scottkosty added a commit to scottkosty/test_that that referenced this issue Nov 10, 2012

make_expectation now works with more classes
Related to Issue r-lib#24. make_expectation now works with more types of
objects. For example, a data.frame previously lost its data.frame
attribute and was treated as a generic list. The test generated by
make_expectation would thus fail if run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment