Skip to content

convenience function for expect_that #24

Description

@scottkosty

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions