Skip to content

Data() and CSV files

2 messages · McGehee, Robert, Peter Dalgaard

#
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?

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?

Thanks,
Robert
#
"McGehee, Robert" <Robert.McGehee at geodecapital.com> writes:
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().
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.