Read Comma-Separated Text Data Files
csv.get.RdRead comma-separated text data files, allowing optional translation
to lower case for variable names after making them valid S names.
There is a facility for reading long variable labels as one of the
rows. If labels are not specified and a final variable name is not
the same as that in the header, the original variable name is saved as
a variable label. Uses read.csv if the data.table
package is not in effect, otherwise calls fread.
Usage
csv.get(file, lowernames=FALSE, datevars=NULL, datetimevars=NULL,
dateformat='%F',
fixdates=c('none','year'), comment.char="", autodate=TRUE,
allow=NULL, charfactor=FALSE,
sep=',', skip=0, vnames=NULL, labels=NULL, text=NULL, ...)Arguments
- file
the file name for import.
- lowernames
set this to
TRUEto change variable names to lower case.- datevars
character vector of names (after
lowernamesis applied) of variables to consider as a factor or character vector containing dates in a format matchingdateformat. The default is"%F"which uses the yyyy-mm-dd format.- datetimevars
character vector of names (after
lowernamesis applied) of variables to consider to be date-time variables, with date formats as described underdatevarsfollowed by a space followed by time in hh:mm:ss format.chronis used to store such variables. If all times in the variable are 00:00:00 the variable will be converted to an ordinary date variable.- dateformat
for
cleanup.importis the input format (seestrptime)- fixdates
for any of the variables listed in
datevarsthat have adateformatthatcleanup.importunderstands, specifyingfixdatesallows corrections of certain formatting inconsistencies before the fields are attempted to be converted to dates (the default is to assume that thedateformatis followed for all observation fordatevars). Currentlyfixdates='year'is implemented, which will cause 2-digit or 4-digit years to be shifted to the alternate number of digits whendateformis the default"%F"or is"%y-%m-%d","%m/%d/%y", or"%m/%d/%Y". Two-digits years are padded with20on the left. Setdateformatto the desired format, not the exceptional format.- comment.char
a character vector of length one containing a single character or an empty string. Use '""' to turn off the interpretation of comments altogether.
- autodate
Set to true to allow function to guess at which variables are dates
- allow
a vector of characters allowed by R that should not be converted to periods in variable names. By default, underscores in variable names are converted to periods as with R before version 1.9.
- charfactor
set to
TRUEto change character variables to factors if they have fewer than n/2 unique values. Blanks and null strings are converted toNAs.- sep
field separator, defaults to comma
- skip
number of records to skip before data start. Required if
vnamesorlabelsis given.- vnames
number of row containing variable names, default is one
- labels
number of row containing variable labels, default is no labels
- text
a character string containing the
.csvfile to use instead offile=. Passed toread.csvas thetext=argument.- ...
arguments to pass to
read.csvother thanskipandsep.
Details
csv.get reads comma-separated text data files, allowing optional
translation to lower case for variable names after making them valid S
names. Original possibly non-legal names are taken to be variable
labels if labels is not specified. Character or factor
variables containing dates can be converted to date variables.
cleanup.import is invoked to finish the job.
See also
sas.get, data.frame,
cleanup.import, read.csv,
strptime, POSIXct, Date,
fread