setrt: Set working directory, starting from a custom root directory

Description Usage Arguments Details Note Examples

View source: R/setwdrt.R

Description

Basic usage: use setrt(dir) to set a custom root; use setwdrt(dir) to, roughly-speaking, setwd(paste0(customRroot, dir)). Advanced usage: use setrt(dir,name = "rootName") to name a custom root; use setrt(name = "rootName") to switch the primary root to that named custom root; use getrts() to list all available custom roots and their names.

Usage

1
2
3
4
5
setrt(dir = NULL, name = "")

setwdrt(dir = "", name = "")

getrts()

Arguments

dir

directory. In setrt if this is NULL, then name must be specified, and setrt makes the primary root the named custom root.

name

name of custom root; defaults to "", which is the "current project root"

Details

Best way to use these functions is:

An error is thrown if a particular custom root has not be defined but is called by setwdrt().

Note

Internally, these functions use a series of options that look like paste0(name,"dismisc_root"). Therefore, these custom roots survive remove(list=ls()) and other modifications to the global environment (in the same way that attached libraries do), so it is reasonable to put them in init.R and run them once when you start working on the project.

If in calling setrt() no forward slash '/' is given at the end of dir, a forward slash '/' is appended.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Not run: 

# Basic usage
setrt("~/Dropbox/myproject/") # set the root directory to myproject
setwdrt('data') # set the current working directory to ~/Dropbox/myproject/data/

# Advanced usage
setrt("~/Dropbox/myproject/",name='main') # create a named custom root, 'main'
setrt("~/Dropbox/old/project/on/which/this/proj/depends/",name='dependsOn') # create a named custom root called 'dependsOn

setrt(name='main') # now the primary project root is 'main'
setwdrt("data")
# do some work in the ~/Dropbox/myproject/data/ directory...

setrt(name='dependsOn') # now the primary project root is 'dependsOn'
setwdrt("data")
# do some work in (e.g. get some data from) the ~/Dropbox/old/project/on/which/this/proj/depends/data directory

getrts() # show all defined custom roots, in this case, 'main' and 'dependsOn'


## End(Not run)

rdisalv2/dismisc documentation built on March 19, 2018, 9:12 a.m.