Description Usage Arguments Value See Also Examples
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ## 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())
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.