View source: R/tbl_check_class.R
tbl_check_class | R Documentation |
Checks if object
and expected
have the same class.
If the classes differ
tbl_check_class()
and vec_check_class()
return a list describing
the problem
tbl_grade_class()
and vec_grade_class()
return a failing grade and
informative message with gradethis::fail()
tbl_check_class( object = .result, expected = .solution, ignore_class = NULL, env = parent.frame() ) vec_check_class( object = .result, expected = .solution, ignore_class = NULL, env = parent.frame() ) tbl_grade_class( object = .result, expected = .solution, ignore_class = NULL, env = parent.frame(), ... ) vec_grade_class( object = .result, expected = .solution, ignore_class = NULL, env = parent.frame(), ... )
object |
An object to be compared to |
expected |
An object containing the expected result. |
ignore_class |
If an element is named, differences will only be ignored between the pair
of the element and its name.
For example, If all the classes of |
env |
The environment in which to find |
... |
Arguments passed on to
|
If there are any issues, a list from tbl_check_class()
and
vec_check_class()
or a gradethis::fail()
message from
tbl_grade_class()
and vec_grade_class()
.
Otherwise, invisibly returns NULL
.
class
: The object does not have the expected classes
.result <- 1:10 .solution <- as.character(1:10) vec_check_class() vec_grade_class() .result <- data.frame(a = 1:10) .solution <- tibble::tibble(a = 1:10) tbl_check_class() tbl_grade_class() .result <- tibble::tibble(a = 1:10, b = a %% 2 == 0) .solution <- dplyr::group_by(tibble::tibble(a = 1:10, b = a %% 2 == 0), b) tbl_check_class() tbl_grade_class() # Ignore the difference between tibble and data frame .result <- data.frame(a = 1:10) .solution <- tibble::tibble(a = 1:10) tbl_check_class(ignore_class = c("tbl_df", "tbl")) tbl_grade_class(ignore_class = c("tbl_df", "tbl")) # Ignore the difference between integer and double .result <- 1L .solution <- 1 vec_check_class(ignore_class = c("integer" = "numeric")) vec_grade_class(ignore_class = c("integer" = "numeric"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.