read.file(f=NULL,header=TRUE,...) #for .txt, .text, .csv, .sav, .rds, or .rda files
read.clipboard(header = TRUE, ...) #assumes headers and tab or space delimited
read.clipboard.csv(header=TRUE,sep=',',...) #assumes headers and comma delimited
read.clipboard.tab(header=TRUE,sep='\t',...) #assumes headers and tab delimited #read in a matrix given the lower off diagonal read.clipboard.lower(diag=TRUE,names=FALSE,...) read.clipboard.upper(diag=TRUE,names=FALSE,...)
#read in data using a fixed format width (see read.fwf for instructions)
read.clipboard.fwf(header=FALSE,widths=rep(1,10),...)
read.https(filename,header=TRUE)
read.file.csv(f=NULL,header=TRUE,...)
write.file(x,f=NULL,row.names=FALSE,...)
write.file.csv(x,f=NULL,row.names=FALSE,...)
The read.file
function combines the file.choose
and either read.table
or read.spss
(from foreign) or load
or readRDS
commands. By examining the file suffix, it chooses the appropriate way to read. For more complicated file structures, see the foreign package.
The write.file
function combines the file.choose
and either write.table
or saveRDS
. By examining the file suffix, it chooses the appropriate way to write. For more complicated file structures, see the foreign package, or the save function in R Base.
read.clipboard
was based upon a suggestion by Ken Knoblauch to the R-help listserve.
If the input file that was copied into the clipboard was an Excel file with blanks for missing data, then read.clipboard.tab() will correctly replace the blanks with NAs. Similarly for a csv file with blank entries, read.clipboard.csv will replace empty fields with NA.
read.clipboard.lower and read.clipboard.upper are adapted from John Fox's read.moments function in the sem package. They will read a lower (or upper) triangular matrix from the clipboard and return a full, symmetric matrix for use by factanal, factor.pa
, ICLUST
, etc. If the diagonal is false, it will be replaced by 1.0s. These two function were added to allow easy reading of examples from various texts and manuscripts with just triangular output.
Many articles will report lower triangular matrices with variable labels in the first column. read.clipboard.lower will handle this case. Names must be in the first column if names=TRUE is specified.
Other articles will report upper triangular matrices with variable labels in the first row. read.clipboard.upper will handle this. Note that labels in the first column will not work for read.clipboard.upper. The names, if present, must be in the first row.
read.clipboard.fwf will read fixed format files from the clipboard. It includes a patch to read.fwf which will not read from the clipboard or from remote file. See read.fwf for documentation of how to specify the widths.
#my.data <- read.file() #search the directory for a file and then read it.
#my.data <- read.clipboad()
#my.data <- read.clipboard.csv()
#my.data <- read.clipboad(header=FALSE)
#my.matrix <- read.clipboard.lower()
Run the code above in your browser using DataLab