[R] packaged datasets in .csv format

Dirk Eddelbuettel edd at debian.org
Wed Jul 9 13:57:50 CEST 2003

On Wed, Jul 09, 2003 at 10:53:27AM +0100, David Firth wrote:
> First, the background.  The data() function loads data from .csv 
> ("comma-separated values") files using
>   read.table(..., header = TRUE, sep = ";")
> But ?read.table says
>      ## To write a CSV file for input to Excel one might use
>      write.table(x, file = "foo.csv", sep = ",", col.names = NA)
>      ## and to read this file back into R one needs
>      read.table("file.csv", header = TRUE, sep = ",", row.names=1)
> As a result, .csv files created by write.table() as above are not read 
> in by data() in the way that might be expected [that is, expected by 
> someone who had not read help(data)!]
> Two questions, then:
> -- is there some compelling reason for  the use of `sep = ";"' in place 
> of `sep = ",", row.names=1'?
> -- if I want to maintain a dataset in .csv format, for use both in R 
> and in other systems such as Excel, SPSS, etc, what is the best way to 
> go about it?

If you include a file  data/foo.csv, also include a file  data/foo.R  as
the .R extension (for code) is examined before the .csv extension for the
data file.  That way, in the .R file you can specify exactly which options
are to be used when the file is loaded.  


Don't drink and derive. Alcohol and analysis don't mix.

More information about the R-help mailing list