It's exciting to see that fread has gained some features that were previously slated as not-likely-to-be-implemented, for instance fill.
However, it seems like fread(..., fill = TRUE) is not happy when the first line is shorter than the longest row.
Using 1.9.7, obviously:
library(data.table)
packageVersion("data.table")
# [1] ‘1.9.7’
Simplest demonstration:
fread("1,a,b\n2", fill = TRUE)
# V1 V2 V3
#1: 1 a b
#2: 2
fread("2\n1,a,b", fill = TRUE)
# Error in fread(paste(invec, collapse = "\n"), ...) :
# Unexpected character ending field 1 of line 1: 2
#1,a,
fread("v1,v2,v3\n2\n1,a,b", fill = TRUE)
# v1 v2 v3
#1: 2
#2: 1 a b
Notice that by adding the column names in to the dataset itself, there is no problem with a shorter first row. So, I thought that using the col.names argument would help out in a situation like this. Unfortunately, it doesn't.
fread("2\n1,a,b", fill = TRUE, col.names = paste0("V", 1:3))
# Error in fread("2\n1,a,b", fill = TRUE, col.names = paste0("V", 1:3)) :
# Unexpected character ending field 1 of line 1: 2
#1,a,
Hope this is enough information to reproduce the behavior on your side too. Wanted to keep the samples simple :-)
It's exciting to see that
freadhas gained some features that were previously slated as not-likely-to-be-implemented, for instancefill.However, it seems like
fread(..., fill = TRUE)is not happy when the first line is shorter than the longest row.Using 1.9.7, obviously:
Simplest demonstration:
Notice that by adding the column names in to the dataset itself, there is no problem with a shorter first row. So, I thought that using the
col.namesargument would help out in a situation like this. Unfortunately, it doesn't.Hope this is enough information to reproduce the behavior on your side too. Wanted to keep the samples simple :-)