datawizard
datawizard copied to clipboard
Fix failing test on windows-devel
── Error (test-convert_to_na.R:90:3): convert_to_na other classes ──────────────
Error in `charToDate(x)`: character string is not in a standard unambiguous format
Backtrace:
â–†
1. ├─testthat::expect_message(...) at test-convert_to_na.R:90:2
2. │ └─testthat:::expect_condition_matching(...)
3. │ └─testthat:::quasi_capture(...)
4. │ ├─testthat (local) .capture(...)
5. │ │ └─base::withCallingHandlers(...)
6. │ └─rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
7. ├─datawizard::convert_to_na(d, na = list(3, "c", TRUE, "2022-01-02"))
8. └─datawizard:::convert_to_na.data.frame(...) at datawizard/R/convert_to_na.R:43:2
9. └─base::lapply(...) at datawizard/R/convert_to_na.R:186:2
10. ├─datawizard (local) FUN(X[[i]], ...)
11. └─datawizard:::convert_to_na.Date(X[[i]], ...) at datawizard/R/convert_to_na.R:43:2
12. ├─base::which(x %in% as.Date(na)) at datawizard/R/convert_to_na.R:137:4
13. ├─x %in% as.Date(na) at datawizard/R/convert_to_na.R:137:4
14. ├─base::as.Date(na) at datawizard/R/convert_to_na.R:137:4
15. └─base::as.Date.character(na)
16. └─base (local) charToDate(x)
I think it's because as.Date()
works for numerics too in R-devel (see this commit), which breaks this:
https://github.com/easystats/datawizard/blob/0a226f69b4b337d8cb8fda1c41b7186024d8f9b7/R/convert_to_na.R#L124-L126
Actually this is the line that causes the issue: https://github.com/easystats/datawizard/blob/0a226f69b4b337d8cb8fda1c41b7186024d8f9b7/R/convert_to_na.R#L137
I don't have R-devel on my laptop so I can't really test this
Given the discussion on R-mailing-list about this change in R-devel, I feel like things are still in a bit of a flux, and so I want to wait for a bit before resolving this and submitting a new version.
Okay, need to fix and submit soon-
Dear maintainer,
Please see the problems shown on https://cran.r-project.org/web/checks/check_results_datawizard.html.
Please correct before 2022-10-27 to safely retain your package on CRAN.
The CRAN Team
No idea how to fix this for now, and as you said it seems that this change is not settled yet on R-devel. If we can't find a solution, one option is to (temporarily) comment this test
I can reproduce with R-devel on Ubuntu. The problem comes from the new behavior of as.Date()
that can now convert numerics to dates:
> as.Date(3)
[1] "1970-01-04"
Here's a reprex where this causes an issue:
test <- data.frame(
num = c(1, 2),
date = as.Date(c("2022-10-17", "2022-10-18"))
)
convert_to_na(test, na = list(1, "2022-10-17"))
#> Error in `charToDate(x)`: character string is not in a standard unambiguous format
This is because in convert_to_na.Date()
, the following lines now return "1" "2022-10-17"
instead of just "2022-10-17"
as before.
unlist(na[sapply(na, function(i) {
!is.null(tryCatch(as.Date(i), error = function(e)
})])
Since this will cause a problem every time there's a numeric in the list specified in na
, I propose that we change the accepted input for convert_to_na.Date()
to accept only objects of class "Date"
. Therefore, the example above should work with convert_to_na(test, na = list(1, as.Date("2022-10-17")))
.
@strengejacke @IndrajeetPatil what do you think?
Thanks for getting to the bottom of this, @etiennebacher.
I propose that we change the accepted input for convert_to_na.Date() to accept only objects of class "Date".
Yes, this sounds like a sensible solution to me.
Agreed.