Usage
readFile(file, fields = TRUE, units = TRUE, sep = "",
encoding = getOption("encoding"))
- file
{character; the name of the file which data will be read from. Alternatively, file
can be a readable text-mode connection
(optional).}
- fields
{logical; if TRUE
the file
contains the names of the variables as its first line.}
- units
{logical; if TRUE
the file
contains the units of the variables as its second line.}
- sep
{character; the field separator string. Values on each line of the file are separated by this string.}
- encoding
{character; encoding to be assumed for input strings. If the value is "latin1"
or "UTF-8"
it is used to mark character strings as known to be in Latin-1 or UTF-8: it is not used to re-encode the input.}
A tab delineated text file containing at least the following variables:
[object Object],[object Object]
The first [1,]
and second [2,]
rows are reserved for column descriptors and units, respectively.
Units associated with date-time values are based on format character strings described in strptime
,
for example "02/26/2010 02:05:39 PM" is represented using "%d/%m/%Y %I:%M:%S %p".
You may embed comments in the data file by using the #}}
character string; anything after a #}} on a line will be ignored.
The NA
character string is interpreted as a NA
value.
For example, a data file containing a header and three rows of data might look like:
lrrrrl{
# Ignored character string \tab \tab \tab \tab \tab \cr
Date Time X Y Z Concentration # Column names\cr
%Y-%m-%d %H:%M:%OS m m m mg/L # Column units\cr
2008-02-03 10:43:38.275 7.83 -2.3 0.2650 6.211E-6
2008-04-24 11:20:43.757 15.01 8.1 NA 3.135E-5 # Comment\cr
2009-04-25 13:02:11.123 -4.73 23.7 0.3790 1.729E-6 }
Returns a list with the following components:
- dat
{data.frame; a table of data}
- cols
{character; a vector of column names}
- vars
{character; a vector giving an initial guess for column names associated with the date-time, x
, y
, and z
variables.}
[object Object],[object Object]
read.table
f <- system.file("RSurvey-ex/DataExample.dat", package = "RSurvey")
con <- file(f, open = "r", encoding = "latin1")
d <- readFile(con)
close(con)
file