Skip to content

read.table

3 messages · Diethelm Wuertz, David Scott, Kjetil Halvorsen

#
Thanks a lot that works fine!

Next problem, if I would have my own package, and the file "test.csv"
would be located in the data directory

How to use the function data to get

 > data(test)

resulting in:

 > test

    %y-%m-%d VALUE
1 1999-01-01   100
2 2000-12-31   999


Again Thanks in advance Diethelm Wuertz
Phil Spector wrote:

            
#
On Tue, 14 Feb 2006, Diethelm Wuertz wrote:

            
I think you might be stuck in a particular mindset about this.

Does the .csv file have to be called test.csv?

If not then if it is called data.csv say, you can have in your data 
directory a file test.R with the code:

read.table("data.csv", header = TRUE, sep = ";", check.names = FALSE)

Alternatively you can have the data in the file test.R, plus the code to 
read it in as desired. Creating a data structure and reading it back in 
with dput and dget is one way to do this.

See page 11 of the Writing R Extensions manual for the possible formats of 
files in the data directory:

"The data subdirectory is for additional data files the package makes 
available for loading using data(). Currently, data files can have one of 
three types as indicated by their extension: plain R code (.R or .r), 
tables (.tab, .txt, or .csv), or save() images (.RData or .rda). (All 
ports of R use the same binary (XDR) format and can read compressed 
images. Use images saved with save(, compress = TRUE) to save space.) Note 
that R code should be self-sufficient and not make use of extra 
functionality provided by the package, so that the data file can also be 
used without having to load the package."

David Scott



_________________________________________________________________
David Scott	Department of Statistics, Tamaki Campus
 		The University of Auckland, PB 92019
 		Auckland	NEW ZEALAND
Phone: +64 9 373 7599 ext 86830		Fax: +64 9 373 7000
Email:	d.scott at auckland.ac.nz


Graduate Officer, Department of Statistics
#
Diethelm Wuertz wrote:
Also put in the data subdirectory the file test.R
with the commands to read  test.csv

Kjetil