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

value is stripped of its class in comparison validation functions #537

Closed
yjunechoe opened this issue Jun 7, 2024 · 0 comments · Fixed by #539
Closed

value is stripped of its class in comparison validation functions #537

yjunechoe opened this issue Jun 7, 2024 · 0 comments · Fixed by #539
Assignees

Comments

@yjunechoe
Copy link
Collaborator

Discovered while investigating #536. Reprex:

agent <- data.frame(date = as.Date(1)) |>
  create_agent() |> 
  col_vals_lt(date, Sys.Date()) |> 
  interrogate()

In the example above, the user might expect col_vals_lt() to compare the column to the value of Sys.Date(), a date object. Instead, I found that it's constructing the expression date < 19881 inside tbl_val_comparison().

I tracked this down to get_values_at_idx() (which is called by interrogate_comparison()). The class stripping happens due to the way get_values_at_idx() is written:

pointblank:::get_values_at_idx
#> function (agent, idx) 
#> {
#>     agent$validation_set[[idx, "values"]] %>% unlist(recursive = FALSE)
#> }
#> <bytecode: 0x0000026ee1918a60>
#> <environment: namespace:pointblank>

It seems that unlist() is stripping the value of its class:

agent$validation_set[[1, "values"]]
#> [[1]]
#> [1] "2024-06-07"

class(agent$validation_set[[1, "values"]][[1]])
#> [1] "Date"

agent$validation_set[[1, "values"]] |> unlist()
#> [1] 19881

As far as I can see this isn't producing any bugs on known behaviors, but I thought it'd be nice to try to preserve the class (this may be helpful in tackling #536). But I may also be missing something - please let me know!

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

Successfully merging a pull request may close this issue.

2 participants