[R] read.csv to read output of system()?

Marianne Promberger marianne.promberger at kcl.ac.uk
Sat Dec 12 13:54:59 CET 2009


Dear list,

I have a file that is comma delimited but contains some erroneous
non-delimiter commas. I would like to replace these commas with
semicolons and then read the correct file into R as a data frame.

I want to do this from within R, without changing the original data
file.

My current idea of how to do this would be to use system("sed ...")
and feed the result to read.csv(), but I cannot figure out how to
combine the two.

Minimal example:

system("echo \"one,two,three\" > file.csv") # create mockup file
read.csv(file=system("sed -e 's/,/;/' file.csv"))  # this does not work

I think the answer must be in ?connections, maybe pipe() but I have
fiddled with these and cannot figure it out.

Marianne

-- 
Marianne Promberger PhD, King's College London
http://promberger.info
R version 2.10.0 (2009-10-26)
Ubuntu 9.04




More information about the R-help mailing list