setup*
functions that are contained within setupProject
R/setupProject.R
setup.Rd
These functions will allow more user control, though in most circumstances, it should be unnecessary to call them directly.
setupPaths(
name,
paths,
inProject,
standAlone = TRUE,
libPaths = NULL,
updateRprofile = getOption("Require.updateRprofile", FALSE),
overwrite = FALSE,
envir = environment(),
verbose = getOption("Require.verbose", 1L),
dots,
defaultDots,
...
)
setupSideEffects(
name,
sideEffects,
paths,
times,
overwrite = FALSE,
envir = environment(),
verbose = getOption("Require.verbose", 1L),
dots,
defaultDots,
...
)
setupOptions(
name,
options,
paths,
times,
overwrite = FALSE,
envir = environment(),
verbose = getOption("Require.verbose", 1L),
dots,
defaultDots,
...
)
setupModules(
name,
paths,
modules,
useGit = getOption("SpaDES.project.useGit", FALSE),
overwrite = FALSE,
envir = environment(),
verbose = getOption("Require.verbose", 1L),
dots,
defaultDots,
...
)
setupPackages(
packages,
modulePackages,
require,
libPaths,
setLinuxBinaryRepo = TRUE,
standAlone,
envir = environment(),
verbose,
dots,
defaultDots,
...
)
setupParams(
name,
params,
paths,
modules,
times,
options,
overwrite = FALSE,
envir = environment(),
verbose = getOption("Require.verbose", 1L),
dots,
defaultDots,
...
)
setupGitIgnore(
paths,
gitignore = getOption("SpaDES.project.gitignore", TRUE),
verbose
)
setupStudyArea(studyArea, paths, envir)
Optional. If supplied, the name of the project. If not supplied, an
attempt will be made to extract the name from the paths[["projectPath"]]
.
If this is a GitHub project, then it should indicate the full Github
repository and branch name, e.g., "PredictiveEcology/WBI_forecasts@ChubatyPubNum12"
a list with named elements, specifically, modulePath
, projectPath
,
packagePath
and all others that are in SpaDES.core::setPaths()
(i.e., inputPath
, outputPath
, scratchPath
, cachePath
, rasterTmpDir
).
Each of these has a sensible default, which will be overridden but any user
supplied values.
See setup.
A logical. If TRUE
, then the current directory is
inside the paths[["projectPath"]]
.
A logical. Passed to Require::standAlone
. This keeps all
packages installed in a project-level library, if TRUE
. Default is TRUE
.
Deprecated. Use paths = list(packagePath = ...)
.
Logical. Should the paths$packagePath
be set in the .Rprofile
file for this project. Note: if paths$packagePath
is within the tempdir()
,
then there will be a warning, indicating this won't persist. If the user is
using Rstudio
and the paths$projectPath
is not the root of the current
Rstudio project, then a warning will be given, indicating the .Rprofile may not
be read upon restart.
Logical vector or character vector, however, only getModule
will respond
to a vector of values. If length-one TRUE
, then all files that were previously downloaded
will be overwritten throughout the sequence of setupProject
. If a vector of
logical or character, these will be passed to getModule
: only the named
modules will be overwritten or the logical vector of the modules.
NOTE: if a vector, no other file specified anywhere in setupProject
will be
overwritten except a module that/those names, because
only setupModules
is currently responsive to a vector. To have fine grained control,
a user can just manually delete a file, then rerun.
An environment within which to look for objects. If called alone,
the function should use its own internal environment. If called from another
function, e.g., setupProject
, then the envir
should be the internal
transient environment of that function.
Numeric or logical indicating how verbose should the function
be. If -1 or -2, then as little verbosity as possible. If 0 or FALSE,
then minimal outputs; if 1
or TRUE, more outputs; 2
even more. NOTE: in
Require
function, when verbose >= 2
, the return object will have an
attribute: attr(.., "Require")
which has lots of information about the
processes of the installs.
Any other named objects passed as a list a user might want for other elements.
A named list of any arbitrary R objects.
These can be supplied to give default values to objects that
are otherwise passed in with the ...
, i.e., not specifically named for these
setup*
functions. If named objects are supplied as top-level arguments, then
the defaultDots
will be overridden. This can be particularly useful if the
arguments passed to ...
do not always exist, but rely on external e.g., batch
processing to optionally fill them. See examples.
further named arguments that acts like objects
, but a different
way to specify them. These can be anything. The general use case
is to create the objects
that are would be passed to
SpaDES.core::simInit
, or SpaDES.core::simInitAndSpades
,
(e.g. studyAreaName
or objects
) or additional objects to be passed to the simulation
(in older versions of SpaDES.core
, these were passed as a named list
to the objects
argument). Order matters. These are sequentially evaluated,
and also any arguments that are specified before the named arguments
e.g., name
, paths
, will be evaluated prior to any of the named arguments,
i.e., "at the start" of the setupProject
.
If placed after the first named argument, then they will be evaluated at the
end of the setupProject
, so can access all the packages, objects, etc.
Optional. This can be an expression or one or more file names or
a code chunk surrounded by {...}
.
If a non-text file name is specified (e.g., not .txt or .R currently),
these files will simply be downloaded, using their relative path as specified
in the github notation. They will be downloaded or accessed locally at that
relative path.
If these file names represent scripts (*.txt or .R), this/these will be parsed and evaluated,
but nothing is returned (i.e., any assigned objects are not returned). This is intended
to be used for operations like cloud authentication or configuration functions
that are run for their side effects only.
Optional. This will be returned if supplied; if supplied, the values
can be used in e.g., params
, e.g., params = list(mod = list(startTime = times$start))
.
See help for SpaDES.core::simInit
.
Optional. Either a named list to be passed to options
or a character vector indicating one or more file(s) to source,
in the order provided. These will be parsed locally (not
the .GlobalEnv
), so they will not create globally accessible objects. NOTE:
options
is run 2x within setupProject
, once before setupPaths
and once
after setupPackages
. This occurs because many packages use options for their
behaviour (need them set before e.g., Require::require
is run; but many packages
also change options
at startup. See details.
See setup.
a character string of modules to pass to getModule
. These
should be one of: simple name (e.g., fireSense
) which will be searched for locally
in the paths[["modulePath"]]
; or a GitHub repo with branch (GitHubAccount/Repo@branch
e.g.,
"PredictiveEcology/Biomass_core@development"
); or a character vector that identifies
one or more (not optional file extension) .R
file(s) (local or GitHub)
to parse that will produce a character vector assigned to
the name "modules". If the entire project is a git repository,
then it will not try to re-get these modules; instead it will rely on the user
managing their git status outside of this function.
See setup.
A logical. If TRUE
, it will use git clone
and git checkout
to get and change branch for each module, according to its specification in
modules
. Otherwise it will download modules with getModules
. NOTE: CREATING A
GIT REPOSITORY AT THE PROJECT LEVEL AND SETTING MODULES AS GIT SUBMODULES IS
NOT YET IMPLEMENTED. IT IS FINE IF THE PROJECT HAS BEEN MANUALLY SET UP TO BE
A GIT REPOSITORY WITH SUBMODULES: THIS FUNCTION WILL ONLY EVALUTE PATHS. This can
be set with the option(SpaDES.project.useGit = xxx)
.
Optional. A vector of packages that must exist in the libPaths
.
This will be passed to Require::Install
, i.e., these will be installed, but
not attached to the search path. See also the require
argument. To force skip
of package installation (without assessing modules), set packages = NULL
A named list, where names are the module names, and the elements
of the list are packages in a form that Require::Require
accepts.
Optional. A character vector of packages to install and attach
(with Require::Require
). These will be installed and attached at the start
of setupProject
so that a user can use these during setupProject
.
See setup
Logical. Should the binary RStudio Package Manager be used on Linux (ignored if Windows)
Optional. Similar to options
, however, this named list will be
returned, i.e., there are no side effects.
See setup.
Logical. Only has an effect if the paths$projectPath
is a git repositories without submodules. This case is ambiguous what a user
wants. If TRUE
, the default, then paths$modulePath
will be added to
the .gitignore
file. Can be controled with options(SpadES.project.gitignore = ...)
.
Optional. If a list, it will be passed to
geodata::gadm
. To specify a country other than the default "CAN"
,
the list must have a named element, "country"
. All other named elements
will be passed to gadm
. 2 additional named elements can be passed for
convenience, subregion = "..."
, which will be grepped with the column
NAME_1
, and epsg = "..."
, so a user can pass an epsg.io
code to
reproject the studyArea
. See examples.
setupPaths
returns a list of paths that are created. projectPath
will be
assumed to be the base of other non-temporary and non-R-library paths. This means
that all paths that are directly used by simInit
are assumed to be relative
to the projectPath
. If a user chooses to specify absolute paths, then they will
be returned as is. It is also called for its
side effect which is to call setPaths
, with each of these paths as an argument.
See table for details.
setupSideEffects
is run for its side effects (e.g., web authentication, custom package
options that cannot use base::options
), with deliberately nothing returned to user.
This, like other parts of this function, attempts to prevent unwanted outcomes
that occur when a user uses e.g., source
without being very careful about
what and where the objects are sourced to.
setupOptions
is run for its side effects, namely, changes to the options()
. The
list of modified options will be added as an attribute (attr(out, "projectOptions")
),
e.g., so they can be "unset" by user later.
setupModules
is run for its side effects, i.e., downloads modules and puts them
into the paths[["modulePath"]]
. It will return a named list, where the names are the
full module names and the list elemen.ts are the R packages that the module
depends on (reqsPkgs
)
setupPackages
is run for its side effects, i.e., installing packages to
paths[["packagePath"]]
.
setupParams
prepares a named list of named lists, suitable to be passed to
the params
argument of simInit
.
setupGitIgnore
is run for its side effects, i.e., adding either paths$packagePath
and/or paths$modulePath
to the
.gitignore
file. It will check whether packagePath
is located inside the
paths$projectPath
and will add this folder to the .gitignore
if TRUE
.
If the project is a git repository with git submodules, then it will add nothing else.
If the project is a git repository without git submodules, then the paths$modulePath
will be added to the .gitignore
file. It is assumed that these modules are
used in a read only
manner.
setupStudyArea
will return an sf
class object coming from geodata::gadm
,
with subregion specification as described in the studyArea
argument.fsu
setPaths
will fill in any paths that are not explicitly supplied by the
user as a named list. These paths that can be set are:
projectPath
, packagePath
, cachePath
, inputPath
,
modulePath
, outputPath
, rasterPath
, scratchPath
, terraPath
.
These are grouped thematically into three groups of paths:
projectPath
and packagePath
affect the project, regardless
of whether a user uses SpaDES modules. cachePath
, inputPath
, outputPath
and
modulePath
are all used by SpaDES within module contexts. scratchPath
,
rasterPath
and terraPath
are all "temporary" or "scratch" directories.
Most arguments in the family of setup*
functions are run sequentially, even within
the argument. Since most arguments take lists, the user can set values at a first
value of a list, then use it in calculation of the 2nd value and so on. See
examples. This "sequential" evaluation occurs in the ...
, setupSideEffects
, setupOptions
,
setupParams
(this does not work for setupPaths
) can handle sequentially
specified values, meaning a user can
first create a list of default options, then a list of user-desired options that
may or may not replace individual values. This can create hierarchies, based on
order.
setupOptions
can handle sequentially specified values, meaning a user can
first create a list of default options, then a list of user-desired options that
may or may not replace individual values. Thus final values will be based on the
order that they are provided.
setupModules
will download all modules do not yet exist locally. The current
test for "exists locally" is simply whether the directory exists. If a user
wants to update the module, overwrite = TRUE
must be set, or else the user can
remove the folder manually.
setupPackages
will read the modules' metadata reqdPkgs
element. It will combine
these with any packages passed manually by the user to packages
, and pass all
these packages to Require::Install(...)
.
setupGitIgnore
will add.
setupStudyArea
only uses inputPath
within its paths
argument, which will
be passed to path
argument of gadm
. User can pass any named list element
that matches the columns in the sf
object, including e.g., NAME_1
and, if level = 2
,
is specified, then NAME_2
.
Path | Default if not supplied by user | Effects |
Project Level Paths | ||
projectPath | if getwd() is name , then just getwd ; if not
file.path(getwd(), name) | If current project is not this project
and using Rstudio , then the current
project will close and a new project will
open in the same Rstudio session, unless
Restart = FALSE |
packagePath | file.path(tools::R_user_dir("data"), name, "packages", version$platform, substr(getRversion(), 1, 3)) | appends this path to .libPaths(packagePath) ,
unless standAlone = TRUE , in which case,
it will set .libPaths(packagePath, include.site = FALSE) to this path |
------ | ----------- | ----- |
Module Level Paths | ||
cachePath | file.path(projectPath, "cache") | options(reproducible.cachePath = cachePath) |
inputPath | file.path(projectPath, "inputs") | options(spades.inputPath = inputPath) |
modulePath | file.path(projectPath, "modules") | options(spades.inputPath = outputPath) |
outputPath | file.path(projectPath, "outputs") | options(spades.inputPath = modulePath) |
------ | ----------- | ----- |
Temporary Paths | ||
scratchPath | file.path(tempdir(), name) | |
rasterPath | file.path(scratchPath, "raster") | sets (rasterOptions(tmpdir = rasterPath) ) |
terraPath | file.path(scratchPath, "terra") | sets (terraOptions(tempdir = terraPath) ) |
------ | ----------- | ----- |
Other Paths | ||
logPath | file.path(outputPath(sim), "log") | sets options("spades.logPath") accessible by logPath(sim) |
tilePath | Not implemented yet | Not implemented yet |