sfirke/janitor

`get_one_to_one()` errors with duplicated dttm

olivroy opened this issue · 4 comments

library(fs)
janitor::get_one_to_one(fs::dir_info())

Please briefly describe your problem and what output you expect.

fs::dir_info() |> janitor::get_one_to_one()
#> Error in `levels<-`(`*tmp*`, value = as.character(levels)):   factor level [5] is duplicated

Created on 2023-05-26 with reprex v2.0.2

This only seems to occur with duplicated dates, in this case with columns at position 5, 16, 17.

Thanks for reporting this. It does appear to be an error in the code, but I can't reproduce it because I don't have your fs::dir_info() output. Can you please make a minimal reproducible example where the input data is part of the reprex?

Hi, here is a the reproducible example (with dput)

dates <- structure(list(modification_time = structure(c(1684261364.85967, 
                                               1684274880.48328, 1684261364.85967, 1684418379.74664, 1685105253.21695, 
                                               1684418379.76668, 1684279133.50118, 1684161951.81434, 1684281651.93175, 
                                               1678483898.72893, 1685103626.03424), class = c("POSIXct", "POSIXt"
                                               )), access_time = structure(c(1685040222.34459, 1685041485.59089, 
                                                                             1685105067.68569, 1685040222.51569, 1685105253.21795, 1685105067.73877, 
                                                                             1685105253.66953, 1685106417.48391, 1685105253.66853, 1685041485.59089, 
                                                                             1685103652.82275), class = c("POSIXct", "POSIXt")), change_time = structure(c(1684261364.85967, 
                                                                                                                                                           1684274880.48328, 1684261364.85967, 1684418379.74664, 1685105253.21695, 
                                                                                                                                                           1684418379.76668, 1684279133.50118, 1684161951.81434, 1684281651.93175, 
                                                                                                                                                           1678483898.72893, 1685103626.03424), class = c("POSIXct", "POSIXt"
                                                                                                                                                           ))), row.names = c(NA, -11L), class = c("tbl_df", "tbl", "data.frame"
                                                                                                                                                           )) 
janitor::get_one_to_one(dates)
Error in `levels<-`(`*tmp*`, value = as.character(levels)) : 
  factor level [5] is duplicated

The underlying issue is unusual here. What is happening is that the times with 5 decimal place precision differ but when converted by factor, they lose that precision and become the same.

thanks for reporting this @olivroy and for fixing @billdenney !