coder
coder copied to clipboard
Error when calling categorize() with codify_args
A simple example based on README/Usage fails with an error I can't decipher. Am I doing something silly?
> library(coder)
Warning message:
package ‘coder’ was built under R version 4.3.3
> m <- data.frame(UID=c("0000"), SUPP_DATE=as.Date("2024-01-01"), ATC_CODE=c("C09CA07"))
> cc <- data.frame(UID=c("0000"), SUPP_DATE=as.Date("2024-01-02"))
> ch <- categorize(cc, codedata=m, cc="rxriskv", id="UID", code="ATC_CODE",
+ codify_args = list(date="SUPP_DATE", code_date="SUPP_DATE", days=c(-365, -1)))
Classification based on: atc_pratt
Error in `[.data.frame`(y, , c(id, setdiff(names(y), id))) :
undefined columns selected
> sessionInfo()
R version 4.3.2 (2023-10-31 ucrt)
[...]
[1] coder_0.13.10
loaded via a namespace (and not attached):
[1] compiler_4.3.2 magrittr_2.0.3 cli_3.6.2 generics_0.1.3
[5] tools_4.3.2 pillar_1.9.0 glue_1.7.0 decoder_1.2.2
[9] tibble_3.2.1 utf8_1.2.4 fansi_1.0.6 vctrs_0.6.5
[13] data.table_1.15.0 lifecycle_1.0.4 pkgconfig_2.0.3 rlang_1.1.3
OK, this works, so it appears that the date and supp_date variables must have different names:
> library(coder)
Warning message:
package ‘coder’ was built under R version 4.3.3
> m <- data.frame(UID=c("0000"), SUPP_DATE=as.Date("2024-01-01"), ATC_CODE=c("C09CA07"))
> cc <- data.frame(UID=c("0000"), S_DATE=as.Date("2024-01-02"))
> ch <- categorize(cc, codedata=m, cc="rxriskv", id="UID", code="ATC_CODE",
+ codify_args = list(date="S_DATE", code_date="SUPP_DATE", days=c(-365, -1)))