swd {pkgutils}R Documentation

Change or list working directories

Description

Set the working directory to, e.g., a parent directory of the current one, or to a directory visited earlier. Alternatively, list the working directories stored by using swd, or just the current working directory if swd has not been called yet. These are mainly convenience functions for interactive sessions.

Usage

  swd(x)

  ## S3 method for class 'NULL'
 swd(x)

  ## S3 method for class 'character'
 swd(x)

  ## S3 method for class 'numeric'
 swd(x)

  listwd(x)

  ## S3 method for class 'NULL'
 listwd(x)

  ## S3 method for class 'numeric'
 listwd(x)

Arguments

x

For swd, a numeric scalar indicating how often to move upwards (i.e., to which parent directory, or character vector containing directory names, or NULL. If x is a negative number, this is used to go to one of the working directories used earlier, using an internally stored directory list. That is, if n is a numeric scalar, the action of swd(n) is not necessarily the inverse of what swd(-n) is doing.

If x is a character vector, its elements passed in turn to setwd.

For listwd, x is an optional numeric scalar indicating how many directories (maximally) to show. The default is 10.

Value

swd yields NULL, returned invisibly. As a side effect, the name of the resulting working directory is printed. This is the only action if x is NULL. The directory stack registers a new directory only via calls to swd itself, not via setwd.

For listwd, a character vector with directory names (current one last), returned invisibly. As a side effect, the list of at most x last directories is printed together with the numeric indexes that would be needed to set them using swd, respectively.

See Also

base::setwd base::getwd

Examples

## listwd()
(d1 <- getwd())
## [1] "/home/goeker/Documents/SVN_opm/trunk/pkgutils_doc/manual"
x <- listwd()
##   0 /home/goeker/Documents/SVN_opm/trunk/pkgutils_doc/manual
stopifnot(x == d1)
swd(1)
## /home/goeker/Documents/SVN_opm/trunk/pkgutils_doc
x <- listwd()
##  -1 /home/goeker/Documents/SVN_opm/trunk/pkgutils_doc/manual
##   0 /home/goeker/Documents/SVN_opm/trunk/pkgutils_doc
stopifnot(x == c(d1, dirname(d1)))
swd(-1)
## /home/goeker/Documents/SVN_opm/trunk/pkgutils_doc/manual
x <- listwd()
##  -2 /home/goeker/Documents/SVN_opm/trunk/pkgutils_doc/manual
##  -1 /home/goeker/Documents/SVN_opm/trunk/pkgutils_doc
##   0 /home/goeker/Documents/SVN_opm/trunk/pkgutils_doc/manual
stopifnot(x == c(d1, dirname(d1), d1))

## swd()
(d1 <- getwd())
## [1] "/home/goeker/Documents/SVN_opm/trunk/pkgutils_doc/manual"
swd(1) # got to immediate parent directory
## /home/goeker/Documents/SVN_opm/trunk/pkgutils_doc
stopifnot(d1 != getwd(), dirname(d1) == getwd())
swd(d1) # go back, using a name
## /home/goeker/Documents/SVN_opm/trunk/pkgutils_doc/manual
stopifnot(d1 == getwd())
swd(1) # go upwards again
## /home/goeker/Documents/SVN_opm/trunk/pkgutils_doc
stopifnot(d1 != getwd(), dirname(d1) == getwd())
swd(-1) # go back, using the position within the visited directories
## /home/goeker/Documents/SVN_opm/trunk/pkgutils_doc/manual
stopifnot(d1 == getwd())
swd(-2) # go back, using the position again
## /home/goeker/Documents/SVN_opm/trunk/pkgutils_doc/manual
stopifnot(d1 == getwd())

[Package pkgutils version 0.7.63 Index]