Learn R Programming

RSurvey (version 0.6-0)

ReadData: Read Data

Description

Reads table formatted data from a connection and creates a data frame from it.

Usage

ReadData(con, headers = c(FALSE, FALSE, FALSE), sep = "", 
         quote = ""'", nrows = -1, na.strings = c("", "NA"), 
         skip = 0, comment.char = "#", 
         encoding = getOption("encoding"), parent = NULL)

con{connection; a connection object.}
headers{logical; a vector of length three that indicates whether the 
  data table contains header lines: see Details.}
sep{character; the field separator string. Values on each line of the 
  file are separated by this string.}
quote{character; the set of quoting characters.}
nrows{integer; the maximum number of rows to read in. Negative and other 
  invalid values are ignored (optional).}
na.strings{character; a vector of strings which are to be interpreted as 
  NA values. Blank fields are also considered to be missing 
  values.}
skip{integer; the number of lines to skip before beginning to read data.}
comment.char{character; a vector of length one containing a single 
  character or an empty string. Use "" to turn off the interpretation of 
  comments altogether.}
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.}
parent{tkwin; the parent window (optional).}

The table formatted data is required to have at least two numeric variables.
Measurement units associated with date and 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".

This function is the primary method for importing table formatted data. The headers argument, a logical vector of length three, indicates whether the file contains the names, measurement units, and decimal precision of variables as its initial lines of text. For example, a headers = c(TRUE, FALSE, TRUE) indicates that the first and second lines will contain the names and decimal precision of variables, respectively; measurement units are not included. If headers = c(FALSE, FALSE, FALSE) (the default), no header information is contained within the data table.
Returns a list with the following components: dat{data.frame; a data table with headers and comments removed.} cols{list; of length equal to the current number of data variables. Each component in cols is linked to a specific variable (see ManageData).} vars{list; an initial guess of the state variables. Integer components x, y, z, and t specify the index number in cols that correspond to the respective state variable.} [object Object],[object Object] read.table f <- system.file("extdata/DataExample.txt", package = "RSurvey") con <- file(f, open = "r", encoding = "latin1") ans <- ReadData(con, headers = c(TRUE, TRUE, TRUE)) close(con) file

Arguments