Resources are R scripts that optionally have a "parser" attached which takes the result of executing the file, including all of its local variables, and does some additional computation. This is useful if, for example, you are trying to define a standard format for creating a reference class object by specifying some inputs, but want to make it easy to provide those inputs by users.
resource(name, ..., defining_environment. = parent.frame())
name | character. The name of the resource (i.e. R script) relative to the root of the director object. |
---|---|
provides | list or environment. A list or environment of values to provide
to the resource. The default is nothing, i.e., |
body | logical. Whether or not to fetch the body of the resource. |
soft | logical. Whether or not to modify the cache to reflect the resource modification time and other details. |
tracking | logical. Whether or not to perform modification tracking by pushing accessed resources to the director's stack. |
helper | logical. If If |
A directorResource
object.
This method will return a directorResource
object that represents
that particular R script. A resource can have a preprocessor
and a link[=register_parser]{parser}
attached to it.
The former determines how to source the R file. For example, if you need to inject additional variables prior to sourcing it, you can do so from the preprocessor.
The parser determines what to do with the R file after sourcing it. It can tell what the dependencies of the file are (i.e., what other resources were used when sourcing it), and whether or not it was modified (i.e., whether the R file or any of its dependencies were modified).
Together, a preprocessor, parser, and source file compose a resource.