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

Closed
scottkosty opened this issue Oct 25, 2011 · 1 comment
Closed

convenience function for expect_that #24

scottkosty opened this issue Oct 25, 2011 · 1 comment

Comments

@scottkosty
Copy link

@scottkosty 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"))
        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")))
@scottkosty scottkosty closed this Oct 26, 2011
@scottkosty scottkosty reopened this Oct 26, 2011
@floybix
Copy link

@floybix floybix commented Jan 4, 2012

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

dput(levels(happiness))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.