-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add ignore_class
argument and ignore grouped_df
if check_groups = FALSE
#109
Conversation
I bumped into this unusual behavior, I don't think it's intended. library(dplyr)
library(tblcheck)
.result <- tibble(a = 1L, b = "2", c = "3")
.solution <- tibble(a = 1, b = 2, c = 3L)
tbl_check(ignore_class = c("numeric" = "integer", "character" = "numeric"))
#> <tblcheck problem>
#> Your `a` column should be a number (class `numeric`), but it is an integer (class `integer`).
#> $ type : chr "class"
#> $ expected : chr "numeric"
#> $ actual : chr "integer"
#> $ expected_length: int 1
#> $ actual_length : int 1
#> $ location : chr "column"
#> $ column : chr "a"
tbl_check(ignore_class = c("numeric" = "integer", "numeric" = "character"))
#> <tblcheck problem>
#> Your `b` column should be a number (class `numeric`), but it is a text string (class `character`).
#> $ type : chr "class"
#> $ expected : chr "numeric"
#> $ actual : chr "character"
#> $ expected_length: int 1
#> $ actual_length : int 1
#> $ location : chr "column"
#> $ column : chr "b" Also after thinking about this more, I wonder if we should skip class checking altogether if, after removing the ignored classes from the set of classes on .result <- tibble(a = 1L, b = "2", c = "3")
.solution <- tibble(a = 1, b = 2, c = 3L)
tbl_check(ignore_class = "numeric") |
R/check_class.R
Outdated
# Replace classes that match named elements of `ignore_class` with the | ||
# element's name. This allows us to ignore differences between the element | ||
# class and the name class. | ||
obj_class_ignored[obj_class_ignored %in% ignore_class[paired]] <- | ||
names(ignore_class[paired])[ | ||
na.omit(match(obj_class_ignored, ignore_class[paired])) | ||
] | ||
exp_class_ignored[exp_class_ignored %in% ignore_class[paired]] <- | ||
names(ignore_class[paired])[ | ||
na.omit(match(exp_class_ignored, ignore_class[paired])) | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do this in a loop to avoid problem of ignore_class("integer" = "numeric", "numeric" = "character")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! 🥳
ignore_class
toclass
checks (and passed bytable
,vector
, andcolumn
checks), specifying class differences to ignore.ignore_class = "glue"
will ignore cases where.result
isglue
/character
and.solution
ischaracter
, or vice versa.ignore_class = c("integer" = "numeric")
will ignore cases where.result
isinteger
and.solution
isnumeric
, or vice versa.grouped_df
class ifcheck_groups = FALSE
.setequal()
instead ofidentical()
, so objects with the same classes in different orders will not trigger aclass
problem.Created on 2022-02-08 by the reprex package (v2.0.1)
Closes #108.