How to import a csv file with a multiline /* C-style block-comment header */ into R -


i looking clever way import csv file specific header format r. header format multiline "c-style" block-comment followed one-line column name header, followed data. looks this:

/* data description: key1: value1 key2: values [...variable number of key-value pairs, may nested...] license:    creative commons attribution 3.0 unported (cc-by) size:   174 data points */ date/time start date/time end    2008-06-01t00:00:00 2008-06-30t23:30:00  2008-07-01t00:00:00 2008-07-31t23:30:00 

for one-off task it's okay manually (counting header lines, n=47):

filelist <- read.tsv(infile, skip = 47, stringsasfactors = false, header = true ) 

...but looking more generic way read in.

(i don't think duplicate question. closest answer have found here this 1 2010.

try this. file called test.csv:

/*comment   */ var,cond,value data,data,data data,data,data data,data,data data,data,data 

code:

con <- file(paste(folder,"test.csv", sep=""),open="r") lines <- readlines(con) start <- match("*/", lines) #gets row index of close comment results <- read.csv(paste(folder,"test.csv", sep=""), head=true, sep=",", skip=start) 

returns:

   var cond value 1 data data  data 2 data data  data 3 data data  data 4 data data  data 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -