Closed thibautjombart closed 5 years ago
The following hack works, but obviously the implementation will need something a bit different ;)
guess_dates <- function(x, ...) {
x <- as.character(x)
to_replace <- !is.na(suppressWarnings(as.integer(x)))
replacement <- lubridate::as_date(
as.integer(x[to_replace]),
origin = as.Date("1900-01-01"))
replacement <- as.character(replacement)
x[to_replace] <- replacement
linelist::guess_dates(x, ...)
}
guess_dates(x, error_tolerance = 1)
The origin currently used in Excel is 1900-01-01 - can't find indications of it being platform-dependent.
The fun thing is that there IS a caveat: on Excel for OSX pre 2011, the origin is 1904 :sweat_smile: https://support.office.com/en-us/article/date-systems-in-excel-e7fe7167-48a9-4b96-bb53-5612a800b487?ui=en-US&rs=en-US&ad=US
Additionally, this is similar to issue #6
Additional question: are the dates above real or contrived? For example: "18/2/10/2018" should not render as a date.
Some dates with inconsistent formats in Excel in a given column end up importd as a
character
containing a mixed bag of numbers and mis-formatted dates such as:It looks like
lubridate::as_date()
can handle this, but we'll need to be able to pass anorigin
argument fromguess_dates()
. The origin currently used in Excel is1900-01-01
- can't find indications of it being platform-dependent.