read.clipboard {psych}R Documentation

shortcut for reading from the clipboard


Input from the clipboard is easy but a bit obscure, particularly for Mac users. This is just an easier way to do so. Data may be copied to the clipboard from Exel spreadsheets, csv files, or fixed width formatted files and then into a data.frame. Data may also be read from lower (or upper) triangular matrices and filled out to square matrices.


read.clipboard(header = TRUE, ...)   #assumes headers and tab or space delimited
read.clipboard.csv(header=TRUE,sep=',',...)   #assumes headers and comma delimited,sep='\t',...)   #assumes headers and tab delimited
 #read in a matrix given the lower off diagonal

#read in data using a fixed format width (see read.fwf for instructions)



Does the first row have variable labels


What is the designated separater between data fields?


for upper or lower triangular matrices, is the diagonal specified or not


for read.clipboard.lower or upper, are colnames in the the first column


how wide are the columns in fixed width input. The default is to read 10 columns of size 1.


Other parameters to pass to read


A typical session of R might involve data stored in text files, generated online, etc. Although it is easy to just read from a file (particularly if using file.choose(), copying from the file to the clipboard and then reading from the clipboard is also very convenient (and somewhat more intuitive to the naive user). This is particularly convenient when copying from a text book or article and just moving a section of text into R.)

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 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, , 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 (or read.clipboard.upper) will handle this case as well.

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.


the contents of the clipboard.


William Revelle

Examples <- read.clipboad() <- read.clipboard.csv() <- read.clipboad(header=FALSE)
#my.matrix <- read.clipboard.lower()

[Package psych version 1.4.5 Index]
Part of the Personality Project      Take our Personality Test