The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 r 1
\name{data}
7224 hornik 2
\alias{data}
16280 hornik 3
\alias{print.packageIQR}
2 r 4
\title{Data Sets}
7224 hornik 5
\description{
14590 hornik 6
  Loads specified data sets, or list the available data sets.
7224 hornik 7
}
2 r 8
\usage{
8099 ripley 9
data(\dots, list = character(0), package = .packages(),
25508 hornik 10
     lib.loc = NULL, verbose = getOption("verbose"),
11
     envir = .GlobalEnv)
4069 hornik 12
}
2 r 13
\arguments{
25543 hornik 14
  \item{\dots}{a sequence of names or literal character strings.}
9439 hornik 15
  \item{list}{a character vector.}
26923 ripley 16
  \item{package}{a character vector giving the packages to look
17
    in for data sets.  By default, all packages in the search path are
26663 ripley 18
    used, then the \file{data} subdirectory (if present) of the current
19242 maechler 19
    working directory.}
16670 hornik 20
  \item{lib.loc}{a character vector of directory names of \R libraries,
21
    or \code{NULL}.  The default value of \code{NULL} corresponds to all
22
    libraries currently known.  If the default is used, the loaded
23
    packages are searched before the libraries.}
11757 hornik 24
  \item{verbose}{a logical.  If \code{TRUE}, additional diagnostics are
25
    printed.}
25508 hornik 26
  \item{envir}{the \link{environment} where the data should be loaded.}
9687 pd 27
}
7224 hornik 28
\value{
16280 hornik 29
  a character vector of all data sets specified, or information about
30
  all available data sets in an object of class \code{"packageIQR"} if
31
  none were specified.
2 r 32
}
4751 hornik 33
\details{
7081 pd 34
  Currently, four formats of data files are supported:
7125 hornik 35
 
7081 pd 36
  \enumerate{
7125 hornik 37
    \item files ending \file{.R} or \file{.r} are
38
    \code{\link{source}()}d in, with the \R working directory changed
7081 pd 39
    temporarily to the directory containing the respective file.
40
 
23590 ripley 41
    \item files ending \file{.RData} or \file{.rda} are
42
    \code{\link{load}()}ed.
43
 
25080 hornik 44
    \item files ending \file{.tab}, \file{.txt} or \file{.TXT} are read
45
    using \code{\link{read.table}(\dots, header = TRUE)}, and hence
46
    result in a data frame.
7081 pd 47
 
23442 ripley 48
    \item files ending \file{.csv} or \file{.CSV} are read using
7125 hornik 49
    \code{\link{read.table}(\dots, header = TRUE, sep = ";")},
50
    and also result in a data frame.
7081 pd 51
  }
23442 ripley 52
  If more than one matching file name is found, the first on this list
53
  is used.
54
 
9439 hornik 55
  The data sets to be loaded can be specified as a sequence of names or
56
  character strings, or as the character vector \code{list}, or as both.
8075 ripley 57
 
26383 hornik 58
  For each given data set, the first two types (\file{.R} or \file{.r},
59
  and \file{.RData} or \file{.rda} files) can create several variables
60
  in the load environment, which might all be named differently from the
61
  data set.  The second two (\file{.tab}, \file{.txt}, or \file{.TXT},
62
  and \file{.csv} or \file{.CSV} files) will always result in the
63
  creation of a single variable with the same name as the data set. 
64
 
14590 hornik 65
  If no data sets are specified, \code{data} lists the available data
25080 hornik 66
  sets.  It looks for a new-style data index in the \file{Meta} or, if
67
  this is not found, an old-style \file{00Index} file in the \file{data}
68
  directory of each specified package, and uses these files to prepare a
69
  listing.  If there is a \file{data} area but no index, available data
70
  files for loading are computed and included in the listing, and a
71
  warning is given: such packages are incomplete.  The information about
72
  available data sets is returned in an object of class
73
  \code{"packageIQR"}.  The structure of this class is experimental.  In
74
  earlier versions of R, an empty character vector was returned along
75
  with listing available data sets.
14590 hornik 76
 
25080 hornik 77
  If \code{lib.loc} is not specified, the data sets are searched for
9687 pd 78
  amongst those packages already loaded, followed by the \file{data}
79
  directory (if any) of the current working directory and then packages
14590 hornik 80
  in the specified libraries.  If \code{lib.loc} \emph{is} specified,
81
  packages are searched for in the specified libraries, even if they are
82
  already loaded from another library.
8099 ripley 83
 
9439 hornik 84
  To just look in the \file{data} directory of the current working
8099 ripley 85
  directory, set \code{package = NULL}.
3998 ripley 86
}
8099 ripley 87
\note{
9439 hornik 88
  The data files can be many small files.  On some file systems it is
89
  desirable to save space, and the files in the \file{data} directory of
90
  an installed package can be zipped up as a zip archive
14590 hornik 91
  \file{Rdata.zip}.  You will need to provide a single-column file
8596 ripley 92
  \file{filelist} of file names in that directory.
9472 pd 93
 
94
  One can take advantage of the search order and the fact that a
9687 pd 95
  \file{.R} file will change directory.  If raw data are stored in
9472 pd 96
  \file{mydata.txt} then one can set up \file{mydata.R} to read
25080 hornik 97
  \file{mydata.txt} and pre-process it, e.g., using \code{transform}.
14590 hornik 98
  For instance one can convert numeric vectors to factors with the
99
  appropriate labels.  Thus, the \file{.R} file can effectively contain
100
  a metadata specification for the plaintext formats.
8099 ripley 101
}
2 r 102
\seealso{
27447 ripley 103
  \code{\link[utils]{help}} for obtaining documentation on data sets,
25080 hornik 104
  \code{\link{save}} for \emph{creating} the second (\file{.rda}) kind
105
  of data, typically the most efficient one.
2 r 106
}
107
\examples{
27541 ripley 108
require(utils)
14590 hornik 109
data()                      # list all available data sets
26666 ripley 110
data(package = "base")      # list the data sets in the base package
25080 hornik 111
data(USArrests, "VADeaths") # load the data sets 'USArrests' and 'VADeaths'
112
help(USArrests)             # give information on data set 'USArrests'
2 r 113
}
975 maechler 114
\keyword{documentation}
286 maechler 115
\keyword{datasets}