newModule | R Documentation |
Generate a skeleton for a new SpaDES module, a template for a
documentation file, a citation file, a license file, a ‘README.md’ file,
and a folder that contains unit tests information. newModule
is largely a
wrapper around newModuleCode
and newModuleDocumentation
.
newModuleCode
will not generate the module code.
newModuleDocumentation
will create the other files.
newModule(name, path, ..., events = NULL, envir = parent.frame())
## S4 method for signature 'character,character'
newModule(name, path, ..., events = NULL, envir = parent.frame())
## S4 method for signature 'character,missing'
newModule(name, path, ..., events = NULL, envir = parent.frame())
newModuleCode(name, path, ..., events)
## S4 method for signature 'character,character'
newModuleCode(name, path, ..., events)
newModuleDocumentation(name, path, ...)
## S4 method for signature 'character,character'
newModuleDocumentation(name, path, ...)
## S4 method for signature 'character,missing'
newModuleDocumentation(name, path, ...)
name |
Character string specifying the name of the new module. |
path |
Character string. Subdirectory in which to place the new module code file. The default is the current working directory. |
... |
Additional arguments. Currently, these can be either named
function definitions (which will be added to the
For
|
events |
A list of named expressions, each of which is surrounded by |
envir |
An environment where objects being passed to |
All files will be created within a subdirectory named name
within the path
:
<path>/ |_ <name>/ |_ R/ # contains additional module R scripts |_ data/ # directory for all included data |_ CHECKSUMS.txt # contains checksums for data files |_ tests/ # contains unit tests for module code |_ citation.bib # bibtex citation for the module |_ LICENSE # describes module's legal usage |_ README.md # provide overview of key aspects |_ <name>.R # module code file (incl. metadata) |_ <name>.Rmd # documentation, usage info, etc.
NULL (invisibly). The new module file is created at ‘path/name.R’, as well as ancillary files for documentation, citation, ‘LICENSE’, ‘README’, and ‘tests’ directory.
newModuleCode
is invoked for its side effect of creating new module code files.
newModuleDocumentation
is nvoked for its side effect of
creating new module documentation files.
On Windows there is currently a bug in RStudio that prevents the editor
from opening when file.edit
is called.
Similarly, in RStudio on macOS, there is an issue opening files where they
are opened in an overlaid window rather than a new tab.
file.edit
does work if the user types it at the command prompt.
A message with the correct lines to copy and paste is provided.
Alex Chubaty and Eliot McIntire
Eliot McIntire and Alex Chubaty
Other module creation helpers:
newModuleTests()
Other module creation helpers:
newModuleTests()
Other module creation helpers:
newModuleTests()
tmpdir <- tempdir2("exampleNewModule")
## create a "myModule" module in the "modules" subdirectory.
newModule("myModule", tmpdir)
## create a new parent module in the "modules" subdirectory.
newModule("myParentModule", tmpdir, type = "parent", children = c("child1", "child2"))
unlink(tmpdir, recursive = TRUE)
if (requireNamespace("ggplot2")) {
# We can also specify events and functions in `newModule`; it will still get all
# functions that are not specified from the module template (e.g., plotFun below)
nm <- "test"
modulePath <- Require::tempdir2()
newModule(nm, path = modulePath, open = FALSE,
events = list(
init = {
sim <- Init(sim) # finds definition below
sim <- scheduleEvent(sim, start(sim) + 1,
eventType = "plot")
},
plot = {
plotFun(sim) # finds the templated plotFun
sim <- scheduleEvent(sim, time(sim) + 1,
eventType = "plot")
}
,
),
Init = function(sim) { # replaces Init definition from template
sim$a <- 1
return(sim)
}
)
out <- simInitAndSpades(module = nm, paths = list(modulePath = modulePath))
# clean up
unlink(dir(modulePath, pattern = nm, full.names = TRUE), recursive = TRUE)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.