alexsanjoseph / compareDF

R Tool to compare two data.frames
Other
93 stars 17 forks source link

Error in as.Date.numeric(value) : 'origin' must be supplied #46

Closed jaw8 closed 2 years ago

jaw8 commented 2 years ago

Describe the bug When setting keep_unchanged_rows = T an error occurs: Error in as.Date.numeric(value) : 'origin' must be supplied

To Reproduce Steps to reproduce the behavior: Normal call of

compareDF::compare_df(...,
                      keep_unchanged_rows = T
                      )

Setting/keeping default keep_unchanged_rows = F does NOT error.

Expected behavior No error is expected.

Screenshots image.

Desktop (please complete the following information):

Additional context None.

alexsanjoseph commented 2 years ago

Can you give me a full reprex?

jaw8 commented 2 years ago

Reprex below. Thank you!

library(compareDF)

df_new <- structure(
  list(`Subject Id` = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L),
                                     .Label = "01-003", 
                                     class = "factor"),
       `Var Group1Row` = c(1, 2, 3, 4, 5, 6, 7, 8, 9), 
       `Start Date` = structure(c(18983, 18983, 18983, 18983, 18983, 18985, 18985, 18991, 19012),
                                class = "Date"), 
       `End Date` = structure(c(NA, 18991, 18991, 18985, 18985, 18991, 18991, 18998, NA),
                              class = "Date"),
       `Severity Grade` = structure(c(1L, 1L, 3L, 3L, 3L, 2L, 2L, 1L, 1L), 
                                    .Label = c("Grade 1 (Mild)", 
                                               "Grade 2 (Moderate)",
                                               "Grade 3 (Severe)"),
                                    class = "factor"), 
       `Con Meds` = c(NA, NA, NA, NA, NA, NA, NA, NA, "6, 7, 10")),
  row.names = c(NA, -9L), class = "data.frame")

df_old <- structure(
  list(`Subject Id` = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L),
                                .Label = "01-003",
                                class = "factor"),
       `Var Group1Row` = c(1, 2, 3, 4, 5, 6, 7, 8, 9),
       `Start Date` = structure(c(18983, 18983, 18983, 18983, 18983, 18985, 18985, 18991, 19012),
                                class = "Date"), 
       `End Date` = structure(c(NA, 18991, 18991, 18985, 18985, 18991, 18991, 18998, NA),
                              class = "Date"), 
       `Severity Grade` = structure(c(1L, 1L, 3L, 3L, 3L, 2L, 2L, 1L, 1L),
                                    .Label = c("Grade 1 (Mild)", 
                                               "Grade 2 (Moderate)", 
                                               "Grade 3 (Severe)"), 
                                    class = "factor"), 
       `Con Meds` = c(NA_character_, NA_character_, NA_character_, 
                      NA_character_, NA_character_, NA_character_, NA_character_, 
                                NA_character_, NA_character_)), 
  row.names = c(NA, -9L), class = "data.frame")

keycols <- c('Subject Id', 'Var Group1Row')

compare_compareDF <-
  compareDF::compare_df(
    df_new = df_new,
    df_old = df_old,
    group_col = keycols,
    keep_unchanged_rows = T,
    change_markers = c("NEW", "OLD", "NO CHANGE")
  )
#> Found factor columns! Will be casted to character for comparison!
#> Found factor columns! Will be casted to character for comparison!
#> Grouping columns
#> Creating comparison table...
#> Error in as.Date.numeric(value): 'origin' must be supplied

Created on 2022-03-14 by the reprex package (v2.0.1)

alexsanjoseph commented 2 years ago

Thanks, seems like a bug while comparing the dates - Will fix this soon. In the meantime, can you fix the example with a smaller reprex? This has 38 rows and is impossible to work with @jaw8

jaw8 commented 2 years ago

Updated reprex.

alexsanjoseph commented 2 years ago

Thanks for the reprex!

Latest version on master should fix this issues. However - will be some time before I can update CRAN because I had an update very recently only. You can install via devtools for now