mscan {Boom} | R Documentation |
Scan a Matrix
Description
Quickly scan a matrix from a file.
Usage
mscan(fname, nc = 0, header = FALSE, burn = 0, thin = 0, nlines = 0L,
sep = "", ...)
Arguments
fname |
The name of the file from which to scan the data. |
nc |
The number of columns in the matrix to be read. If zero then the number of columns will be determined by the number of columns in the first line of the file. |
header |
logical indicating whether the file contains a header row. |
burn |
An integer giving the number of initial lines of the matrix to discard. |
thin |
An integer. If thin > 1 then keep every thin\'th line. This is useful for reading in very large files of MCMC output, for example. |
nlines |
If positive, the number of data lines to scan from the data file (e.g. for an MCMC algorithm that is only partway done). Otherwise the entire file will be read. |
sep |
Field separator in the data file. |
... |
Extra arguments passed to 'scan'. |
Details
This function is similar to read.table
, but scanning a
matrix of homogeneous data is much faster because there is much less
format deduction.
Value
The matrix stored in the data file.
Author(s)
Steven L. Scott steve.the.bayesian@gmail.com
Examples
filename <- file.path(tempdir(), "example.data")
cat("foo bar baz", "1 2 3", "4 5 6", file = filename, sep = "\n")
m <- mscan(filename, header = TRUE)
m
## foo bar baz
## [1,] 1 2 3
## [2,] 4 5 6