swd {pkgutils} | R Documentation |
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.
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)
x |
For If For |
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.
base::setwd base::getwd
## listwd() (d1 <- getwd()) x <- listwd() stopifnot(x == d1) swd(1) x <- listwd() stopifnot(x == c(d1, dirname(d1))) swd(-1) x <- listwd() stopifnot(x == c(d1, dirname(d1), d1)) ## swd() (d1 <- getwd()) swd(1) # got to immediate parent directory stopifnot(d1 != getwd(), dirname(d1) == getwd()) swd(d1) # go back, using a name stopifnot(d1 == getwd()) swd(1) # go upwards again stopifnot(d1 != getwd(), dirname(d1) == getwd()) swd(-1) # go back, using the position within the visited directories stopifnot(d1 == getwd()) swd(-2) # go back, using the position again stopifnot(d1 == getwd())