Virtual resources are those that are not recorded as a .R file. Instead, the resource's value must be computed using a preprocessor.

virtual_check(object, ..., virtual_check.skip = FALSE)

Arguments

object

active_resource. See active_resource.

...

additional parameters to pass to the next layer in the resource parsing tower.

virtual_check.skip

logical. Whether or not to skip the virtual check entirely. Generally only used by internal calls.

Value

The parsed resource.

Details

For example, imagine we have a directory of resources where some of the resources have been re-factored into a package. We would still like to be able to turn objects from that package into proper resources, but they may no longer be encoded as files in the Syberia project.

Instead, we could define a preprocessor that looks for those special values and uses the package objects instead.

When parsing a resource, the local virtual is injected for use in the preprocessor which corresponds to whether the resource seems non-existent to the director (i.e., has no supporting .R file).

Note

The parameters must be named object and ... due to this method's inclusion in a tower.

See also

active_resource, tower

Examples

not_run({ # We will use the example of a syberia project. # See github.com/robertzk/syberia. # lib/mungebits has imputer.R and no other files, but the package # syberiaMungebits has more mungebits. We can define the following # preprocessor. #=== config/routes.R === list( "lib/mungebits" = "mungebits" ) #=== lib/controllers/mungebits.R === preprocessor <- function(resource, virtual) { mungebit <- basename(resource) # lib/mungebits/discretizer becomes discretizer if (virtual) { if (exists(mungebit, envir = getNamespace("syberiaMungebits"), inherits = FALSE)) { # The function exists in the syberiaMungebits package. get(mungebit, envir = getNamespace("syberiaMungebits"))))) } else { stop("No mungebit called ", sQuote(resource)) } } else { source() # Source the mungebit file as usual } } # Construct the mungebit parser as usual. function(output) { mungebits::mungebit(output$train, output$predict) } #=== R console === d <- syberia_project("/some/dir") d$resource("lib/mungebits/imputer") # Will use lib/mungebits/imputer.R d$resource("lib/mungebits/discretizer") # Will use syberiaMungebits::discretizer })
#> Error: <text>:20:67: unexpected ')' #> 19: # The function exists in the syberiaMungebits package. #> 20: get(mungebit, envir = getNamespace("syberiaMungebits"))) #> ^