PipelineTools | R Documentation |
Class definition for pipeline tools
Class definition for pipeline tools
The value of the inputs, or a list if key
is missing
The values of the targets
A PipelineResult
instance if as_promise
or async
is true; otherwise a list of values for input names
An environment of shared variables
See type
A table of the progress
Nothing
ancestor target names (including names
)
A new pipeline object based on the path given
A new pipeline object based on the path given
the saved file path
the data if file is found or a default value
A list of key-value pairs
A list of the preferences. If simplify
is true and length
if keys is 1, then returns the value of that preference
logical whether the keys exist
description
pipeline description
settings_path
absolute path to the settings file
extdata_path
absolute path to the user-defined pipeline data folder
preference_path
directory to the pipeline preference folder
target_table
table of target names and their descriptions
result_table
summary of the results, including signatures of data and commands
pipeline_path
the absolute path of the pipeline
pipeline_name
the code name of the pipeline
new()
construction function
PipelineTools$new( pipeline_name, settings_file = "settings.yaml", paths = pipeline_root(), temporary = FALSE )
pipeline_name
name of the pipeline, usually in the pipeline
'DESCRIPTION'
file, or pipeline folder name
settings_file
the file name of the settings file, where the user inputs are stored
paths
the paths to find the pipeline, usually the parent folder
of the pipeline; default is pipeline_root()
temporary
whether not to save paths
to current pipeline
root registry. Set this to TRUE
when importing pipelines
from subject pipeline folders
set_settings()
set inputs
PipelineTools$set_settings(..., .list = NULL)
..., .list
named list of inputs; all inputs should be named, otherwise errors will be raised
get_settings()
get current inputs
PipelineTools$get_settings(key, default = NULL, constraint)
key
the input name; default is missing, i.e., to get all the settings
default
default value if not found
constraint
the constraint of the results; if input value is not
from constraint
, then only the first element of constraint
will be returned.
read()
read intermediate variables
PipelineTools$read(var_names, ifnotfound = NULL, ...)
var_names
the target names, can be obtained via
x$target_table
member; default is missing, i.e., to read
all the intermediate variables
ifnotfound
variable default value if not found
...
other parameters passing to pipeline_read
run()
run the pipeline
PipelineTools$run( names = NULL, async = FALSE, as_promise = async, scheduler = c("none", "future", "clustermq"), type = c("smart", "callr", "vanilla"), envir = new.env(parent = globalenv()), callr_function = NULL, return_values = TRUE, ... )
names
pipeline variable names to calculate; default is to calculate all the targets
async
whether to run asynchronous in another process
as_promise
whether to return a PipelineResult
instance
scheduler, type, envir, callr_function, return_values, ...
passed to
pipeline_run
if as_promise
is true, otherwise
these arguments will be passed to pipeline_run_bare
eval()
run the pipeline in order; unlike $run()
, this method
does not use the targets
infrastructure, hence the pipeline
results will not be stored, and the order of names
will be
respected.
PipelineTools$eval( names, env = parent.frame(), shortcut = FALSE, clean = TRUE, ... )
names
pipeline variable names to calculate; must be specified
env
environment to evaluate and store the results
shortcut
logical or characters; default is FALSE
, meaning
names
and all the dependencies (if missing from env
)
will be evaluated; set to TRUE
if only names
are to be
evaluated. When shortcut
is a character vector, it should be
a list of targets (including their ancestors) whose values can be assumed
to be up-to-date, and the evaluation of those targets can be skipped.
clean
whether to evaluate without polluting env
...
passed to pipeline_eval
shared_env()
run the pipeline shared library in scripts starting with
path R/shared
PipelineTools$shared_env(callr_function = callr::r)
callr_function
either callr::r
or NULL
; when
callr::r
, the environment will be loaded in isolated R session
and serialized back to the main session to avoid contaminating the
main session environment; when NULL
, the code will be sourced
directly in current environment.
python_module()
get 'Python' module embedded in the pipeline
PipelineTools$python_module( type = c("info", "module", "shared", "exist"), must_work = TRUE )
type
return type, choices are 'info'
(get basic information
such as module path, default), 'module'
(load module and return
it), 'shared'
(load a shared sub-module from the module, which
is shared also in report script), and 'exist'
(returns true
or false on whether the module exists or not)
must_work
whether the module needs to be existed or not. If
TRUE
, the raise errors when the module does not exist; default
is TRUE
, ignored when type
is 'exist'
.
progress()
get progress of the pipeline
PipelineTools$progress(method = c("summary", "details"))
method
either 'summary'
or 'details'
attach()
attach pipeline tool to environment (internally used)
PipelineTools$attach(env)
env
an environment
visualize()
visualize pipeline target dependency graph
PipelineTools$visualize( glimpse = FALSE, aspect_ratio = 2, node_size = 30, label_size = 40, ... )
glimpse
whether to glimpse the graph network or render the state
aspect_ratio
controls node spacing
node_size, label_size
size of nodes and node labels
...
passed to pipeline_visualize
target_ancestors()
a helper function to get target ancestors
PipelineTools$target_ancestors(names, skip_names = NULL)
names
targets whose ancestor targets need to be queried
skip_names
targets that are assumed to be up-to-date, hence
will be excluded, notice this exclusion is
recursive, that means not only skip_names
are excluded,
but also their ancestors will be excluded from the result.
fork()
fork (copy) the current pipeline to a new directory
PipelineTools$fork(path, policy = "default")
path
path to the new pipeline, a folder will be created there
policy
fork policy defined by module author, see text file
'fork-policy' under the pipeline directory; if missing, then default to
avoid copying main.html
and shared
folder
fork_to_subject()
fork (copy) the current pipeline to a 'RAVE' subject
PipelineTools$fork_to_subject( subject, label = "NA", policy = "default", delete_old = FALSE, sanitize = TRUE )
subject
subject ID or instance in which pipeline will be saved
label
pipeline label describing the pipeline
policy
fork policy defined by module author, see text file
'fork-policy' under the pipeline directory; if missing, then default to
avoid copying main.html
and shared
folder
delete_old
whether to delete old pipelines with the same label default is false
sanitize
whether to sanitize the registry at save. This will remove missing folders and import manually copied pipelines to the registry (only for the pipelines with the same name)
with_activated()
run code with pipeline activated, some environment variables
and function behaviors might change under such condition (for example,
targets
package functions)
PipelineTools$with_activated(expr, quoted = FALSE, env = parent.frame())
expr
expression to evaluate
quoted
whether expr
is quoted; default is false
env
environment to run expr
clean()
clean all or part of the data store
PipelineTools$clean( destroy = c("all", "cloud", "local", "meta", "process", "preferences", "progress", "objects", "scratch", "workspaces"), ask = FALSE )
destroy, ask
see tar_destroy
save_data()
save data to pipeline data folder
PipelineTools$save_data( data, name, format = c("json", "yaml", "csv", "fst", "rds"), overwrite = FALSE, ... )
data
R object
name
the name of the data to save, must start with letters
format
serialize format, choices are 'json'
,
'yaml'
, 'csv'
, 'fst'
, 'rds'
; default is
'json'
. To save arbitrary objects such as functions or
environments, use 'rds'
overwrite
whether to overwrite existing files; default is no
...
passed to saver functions
load_data()
load data from pipeline data folder
PipelineTools$load_data( name, error_if_missing = TRUE, default_if_missing = NULL, format = c("auto", "json", "yaml", "csv", "fst", "rds"), ... )
name
the name of the data
error_if_missing
whether to raise errors if the name is missing
default_if_missing
default values to return if the name is missing
format
the format of the data, default is automatically obtained from the file extension
...
passed to loader functions
set_preferences()
set persistent preferences from the pipeline. The preferences should not affect how pipeline is working, hence usually stores minor variables such as graphic options. Changing preferences will not invalidate pipeline cache.
PipelineTools$set_preferences(..., .list = NULL)
..., .list
key-value pairs of initial preference values. The keys
must start with 'global' or the module ID, followed by dot and preference
type and names. For example 'global.graphics.continuous_palette'
for setting palette colors for continuous heat-map; "global" means the
settings should be applied to all 'RAVE' modules. The module-level
preference, 'power_explorer.export.default_format'
sets the
default format for power-explorer export dialogue.
name
preference name, must contain only letters, digits, underscore, and hyphen, will be coerced to lower case (case-insensitive)
get_preferences()
get persistent preferences from the pipeline.
PipelineTools$get_preferences( keys, simplify = TRUE, ifnotfound = NULL, validator = NULL, ... )
keys
characters to get the preferences
simplify
whether to simplify the results when length of key is 1; default is true; set to false to always return a list of preferences
ifnotfound
default value when the key is missing
validator
NULL
or function to validate the values; see
'Examples'
...
passed to validator
if validator
is a function
library(raveio) if(interactive() && length(pipeline_list()) > 0) { pipeline <- pipeline("power_explorer") # set dummy preference pipeline$set_preferences("global.example.dummy_preference" = 1:3) # get preference pipeline$get_preferences("global.example.dummy_preference") # get preference with validator to ensure the value length to be 1 pipeline$get_preferences( "global.example.dummy_preference", validator = function(value) { stopifnot(length(value) == 1) }, ifnotfound = 100 ) pipeline$has_preferences("global.example.dummy_preference") }
has_preferences()
whether pipeline has preference keys
PipelineTools$has_preferences(keys, ...)
keys
characters name of the preferences
...
passed to internal methods
clone()
The objects of this class are cloneable with this method.
PipelineTools$clone(deep = FALSE)
deep
Whether to make a deep clone.
pipeline
## ------------------------------------------------
## Method `PipelineTools$get_preferences`
## ------------------------------------------------
library(raveio)
if(interactive() && length(pipeline_list()) > 0) {
pipeline <- pipeline("power_explorer")
# set dummy preference
pipeline$set_preferences("global.example.dummy_preference" = 1:3)
# get preference
pipeline$get_preferences("global.example.dummy_preference")
# get preference with validator to ensure the value length to be 1
pipeline$get_preferences(
"global.example.dummy_preference",
validator = function(value) {
stopifnot(length(value) == 1)
},
ifnotfound = 100
)
pipeline$has_preferences("global.example.dummy_preference")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.