Skip to content
Prev 4836 / 15075 Next

import data

I agree with Simon that copy paste is the easiest way to go.

However, because I was unable to remember the 
read.table(pipe("pbpaste")) command and wanted to 
give instructions to students that were platform 
independent, I created a little function 
(read.clipboard) that works on PCs or Macs .  It 
is available in the psych package:
"read.clipboard" <-
function(header=TRUE,...) {
     MAC<-Sys.info()[1]=="Darwin"    #are we on a Mac using the Darwin system?
    if (!MAC ) {if (header) 
read.clipboard<-read.table(file("clipboard"),header=TRUE,...)
             else read.clipboard<-read.table(file("clipboard"),...) }
     else {
    if (header) read.clipboard<-  read.table(pipe("pbpaste"),header=TRUE,...)
    else read.clipboard<- read.table(pipe("pbpaste"),...)}
    }

With the addition of  a sep="," option, it can also read csv copied files:


"read.clipboard.csv" <-
function(header=TRUE,sep=',',...) {  #same as read.clipboard(sep=',')
     MAC<-Sys.info()[1]=="Darwin"    #are we on a Mac using the Darwin system?
    if (!MAC ) {if (header) 
read.clipboard<-read.table(file("clipboard"),header=TRUE,sep,...)
             else read.clipboard<-read.table(file("clipboard"),sep,...) }
     else {
    if (header) read.clipboard<- 
read.table(pipe("pbpaste"),header=TRUE,sep,...)
    else read.clipboard<- read.table(pipe("pbpaste") ,sep,...)}
    }


Bill
At 10:53 AM -0400 6/13/08, Simon Urbanek wrote: