Skip to content
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

convenience function for expect_that #24

scottkosty opened this issue Oct 25, 2011 · 1 comment


Copy link

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")))
Copy link

floybix commented Jan 4, 2012

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


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

3 participants