getwd
Get or Set Current Working Directory

Description

Gets or sets the current working directory.

Usage

getwd()
setwd(dir)

Arguments

dir a character string that specifies a directory in the file system.
Value
getwd returns the current working directory. When you specify a character string that is part of a file name on a relative path (non-absolute) for an input or output function, like read.table("data/file.txt"), the search is performed relative to the working directory.
Side Effects
If you use setwd to set the working directory, the current working directory is changed to dir. Non-absolute file references (those starting with a slash on Linux or a letter-colon-slash combination on Windows) are interpreted relative to the working directory.
See Also
normalizePath converts a relative file path to an absolute one.
basename and dirname split a file path into parts.
list.files lists the files in a directory.
Examples
doInDirectory <- function(dir, expr) {
    # move to directory dir,
    # evaluate expr while there,
    # and return to original directory
    curDir <- getwd()
    on.exit(setwd(curDir))
    setwd(dir)
    expr # evaluate argument now (by lazy evaluation)
}
doInDirectory(system.file(package="base"), cat(readLines("DESCRIPTION"), sep="\n"))
Package base version 6.0.0-69
Package Index