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())
## [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())