vroom icon indicating copy to clipboard operation
vroom copied to clipboard

empty column of type date or date-time gives error in R version 3.6.3 with skip = 1

Open philaris opened this issue 2 years ago • 0 comments

In R version 3.6.3, reading data with a date or date-time column and a header when also skipping the first line throws an error.

$ Rscript -e "vroom::vroom(I('date\n'), col_names = 'date', col_types = 'D', skip = 1L)"
Error in as.Date.numeric(double()) : 'origin' must be supplied
Calls: <Anonymous> ... collector_value.collector_date -> as.Date -> as.Date.numeric
Execution halted
$ Rscript -e "vroom::vroom(I('dt\n'), col_names = 'dt', col_types = 'T', skip = 1L)"
Error in as.POSIXct.numeric(double()) : 'origin' must be supplied
Calls: <Anonymous> ... collector_value.collector_datetime -> as.POSIXct -> as.POSIXct.numeric
Execution halted

This is due to the implementation of the numeric converters. E.g.:

$ Rscript -e base::as.Date.numeric
function (x, origin, ...) 
{
    if (missing(origin)) 
        stop("'origin' must be supplied")
    as.Date(origin, ...) + x
}

In newer versions, there is no error, due to the improved implementation:

$ Rscript -e base::as.Date.numeric
function (x, origin, ...) 
{
    if (missing(origin)) {
        if (!length(x)) 
            return(.Date(numeric()))
        if (!any(is.finite(x))) 
            return(.Date(x))
        stop("'origin' must be supplied")
    }
    as.Date(origin, ...) + x
}

I am writing a small fix with tests.

philaris avatar Aug 04 '22 14:08 philaris