|
DATA MINING
Desktop Survival Guide by Graham Williams |
|
|||
Folders and Files |
> getwd() # Identify the current default working directory
> setwd("h:/work/") # Change the current default working directory
> file.exists("filename") # Returns TRUE if the file exists
> unlink("filename") # Deletes the file or directory
> fname <- file.choose() # An interactive file chooser.
> choose.dir() #
> dir <- tclvalue(tkchooseDirectory()) # GUI which requires library(tcltk).
|
List files in a folder in the order by modification time:
> lst <- file.info(dir()) > lst[order(lst$mtime),] |
MS/Windows paths use the backward slash to separate components. This
is a problem since the backslash is used as a standard mechanism for
introducing special characters within strings. Thus, R requires a
double back slash or will seamlessly allow the use of the forward slash.
A useful utility on a MS/Windows environment, where backslashes are
used in paths, and R likes to have forward slashes, is the
following (Duncan Golicher, 5 Jan 2006, r-help):
setwd.clip <- function()
{
options(warn=-1)
setwd(gsub("\\\\", "/",readLines("clipboard")))
options(warn=0)
getwd()
}
|
> dir <- setwd.clip() |
R packages supply files and we can access them in a installation
independent way using XnullXR functionsR functions (R function)R functionsR libraries (R library)R functionsR option (R option)R functionsR packages (R package)R functionsDatasets (Dataset)R functionsR functionssystem.file:
> system.file("csv", "audit.csv", package = "rattle")
|
We can view the contents of files in R using
XnullXR functionsR functions (R function)R functionsR libraries (R library)R functionsR option (R option)R functionsR packages (R package)R functionsDatasets (Dataset)R functionsR functionsfile.show:
> file.show(system.file("csv", "audit.csv", package = "rattle"))
|
Copyright © 2004-2008 Togaware Pty Ltd Support further development through the purchase of the PDF version of the book.