Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

R data.table fread bug

I’m trying to understand data.table’s fread function. I am hoping to read in a csv file, starting at the row where ‘!’ first appears. The number after "!" changes from table to table, but the "!" is a constant feature.

Here’s a version of the data I’m using. When I copy and paste this into a csv file, it works.

113
$LastIndex,AGE_DFN_MORT
!2,PROD_CODE,0,1,2,3,4,5
*,"CDADOA",100,100,100,100,100,100

Here’s my attempt:
fread("<file.location>.csv", skip = "!")

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What I would expect to happen is that the very first column name would be !2, followed by PROD_CODE and so on, however it instead populates all column names with V1, V2, V3 etc.

Have I misunderstood something core about the ‘skip’ argument to the fread function?

EDIT: Thanks – the issue is the absence of the ‘header’ argument

>Solution :

I tried this, it works:

myData <- 
'113
$LastIndex,AGE_DFN_MORT
!2,PROD_CODE,0,1,2,3,4,5
*,"CDADOA",100,100,100,100,100,100'


myData <- fread(myData, skip = '!2', header = TRUE)

myData
#    !2 PROD_CODE   0   1   2   3   4   5
# 1:  *    CDADOA 100 100 100 100 100 100
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading