[R] Reading data

Michael A. Miller mmiller3 at iupui.edu
Fri Sep 25 16:32:58 CEST 2009


Sometimes it is easiest to open a file using a file selection
widget.  I keep this in my .Rprofile:

getOpenFile <- function(...){
  require(tcltk)
  return(tclvalue(tkgetOpenFile()))
}

With this you can find your file and open it with 

  rel <- read.table(getOpenFile(), quote="", header=FALSE, sep="", col.names=c("id","orel","nrel"))

or 

  filename <- getOpenFile()
  rel <- read.table(filename, quote="", header=FALSE, sep="", col.names=c("id","orel","nrel"))

Mike


P.S. I keep a couple functions on hand for choosing writable files
and directories too...

getSaveFile <- function(...){
  require(tcltk)
  return(tclvalue(tkgetSaveFile()))
}

chooseDir <- function(...){
  require(tcltk)
  return(tclvalue(tkchooseDirectory()))
}




More information about the R-help mailing list