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.
1 2 3 4 5
directory. In setrt if this is NULL, then name must be specified, and setrt makes the primary root the named custom root.
name of custom root; defaults to "", which is the "current project root"
Best way to use these functions is:
in your init.R file that you run when you start working on a project
Use setrt(dir) to specify the root folder of your data project as dir
Use setrt(dir, name ="someDependency") to specify the root folder of some dependency (e.g. the data from another project)
in your scripts, when you need to get to a subdirectory
Use setwdrt(dir) to go to that subdirectory; e.g. setwdrt('data') to go to root/data,
Use setwdrt(dir, name = "someDependency") to go to the subdir of that dependency
An error is thrown if a particular custom root has not be defined but is called by setwdrt().
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.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.