here | R Documentation |
here()
constructs file paths starting with this.dir()
.
this.proj()
constructs file paths starting with the project root of
this.dir()
.
reset.proj()
resets the path cache of this.proj()
. This can be
useful if you create a new project that you would like to be detected without
restarting your R session.
here(..., local = FALSE, n = 0,
envir = parent.frame(n + 1),
matchThisEnv = getOption("topLevelEnvironment"),
srcfile = if (n) sys.parent(n) else 0, .. = 0)
this.proj(..., local = FALSE, n = 0,
envir = parent.frame(n + 1),
matchThisEnv = getOption("topLevelEnvironment"),
srcfile = if (n) sys.parent(n) else 0)
reset.proj()
## alias for 'here'
ici(..., local = FALSE, n = 0,
envir = parent.frame(n + 1),
matchThisEnv = getOption("topLevelEnvironment"),
srcfile = if (n) sys.parent(n) else 0, .. = 0)
... |
further arguments passed to |
local , n , envir , matchThisEnv , srcfile |
See
|
.. |
the number of directories to go back. |
For this.proj()
, the project root has the same criterion as
here::here()
, but unlike here::here()
, this.proj()
supports sub-projects and multiple projects in use at once. Additionally,
this.proj()
is independent of working directory, whereas
here::here()
relies on the working directory being set somewhere
within the project when package:here is loaded. Arguably, this makes it
better than here::here()
.
A character vector of the arguments concatenated term-by-term.
tmpdir <- tempfile(pattern = "dir")
dir.create(tmpdir)
writeLines("this file signifies that its directory is the project root",
@R_PACKAGE_NAME@::path.join(tmpdir, ".here"))
FILE.R <- @R_PACKAGE_NAME@::path.join(tmpdir, "src", "R", "script1.R")
dir.create(@R_PACKAGE_NAME@::dirname2(FILE.R), recursive = TRUE)
@R_PACKAGE_NAME@:::.writeCode({
@R_PACKAGE_NAME@::this.path()
@R_PACKAGE_NAME@::this.proj()
## use 'here' to run another script located nearby
@R_PACKAGE_NAME@::here("script2.R")
## or maybe to read input from a file
@R_PACKAGE_NAME@::here(.. = 2, "input", "data1.csv")
## but sometimes it is easier to use the project root
## this allows you to move the R script up or down
## a directory without changing the .. number
@R_PACKAGE_NAME@::this.proj("input", "data1.csv")
}, FILE.R)
source(FILE.R, echo = TRUE)
unlink(tmpdir, recursive = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.