Re: [R] Data() and CSV files

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Thu 28 Apr 2005 - 03:13:12 EST

"McGehee, Robert" <Robert.McGehee@geodecapital.com> writes:

> Hello,
>
> For reasons I don't understand, data() imports CSV (Comma-Separated
> Values) as if they were delimited by semicolons instead of commas. (Are
> semicolon-separated Comma-Separated-Value files common somewhere?) Given
> that this is the case, if I choose to put comma-delimited CSV files in
> my data directory, what is the preferred method of loading these into
> memory?

Semicolon-separated CSV's are common in various parts of Europe, but usually coincident with comma as decimal separator (cf. read.csv/read.csv2). I can't remember whether there was a reason for the choice in data().  

> data("filename")
> would be nice, but not applicable given the above conversion issue.
>
> So, this was the best I came up with:
>
> read.csv(file.path(.find.package("pkg"), "data", paste("filename",
> "csv", sep = ".")))
>
> However, given that others undoubtedly like to include (non-semicolon)
> .csv files in their packages and load them easily, I would like to know
> if there is a more elegant way to load these files. Perhaps an
> annotation in the data/00Index or /data/datalist file that I am unaware
> of?

One trick is that .R files are processed before other files, so a mydata.R file containing mydata <- read.csv("mydata.csv") should do the trick.

It messes with lazy loading of data sets though.

An alternative is to preprocess the data set to (say) .Rda format.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Thu Apr 28 03:19:50 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:27 EST