Config {versioning} | R Documentation |
R6 Class representing a configuration object
Description
R6 Class representing a configuration object
R6 Class representing a configuration object
Details
The special sublist directories
is structured to contain three items for each
directory name:
-
versioned
: a T/F value specifying whether the directory is versioned -
path
: the full path to the top level of that directory. -
files
: A named list referencing file paths within that directory.
If the directory is versioned, a version must be set in the versions
sublist of the
config list. versions
is itself a named list where each key corresponds to a
versioned folder in directories
and the value gives the particular folder version
(for example, a timestamp) that corresponds to the particular run.
Public fields
config_list
The list representation of the Config object
Methods
Public methods
Method new()
Create a new Config object
Usage
Config$new(config_list, versions = NULL)
Arguments
config_list
either a list or a filepath to a YAML file containing that list
versions
(default NULL) A named list containing versions for versioned directories. If passed, used to define or update items in
config_list$versions
.
Method print()
Print the list representation of the Config object
Usage
Config$print()
Method get()
Get a subset of the config_list
Usage
Config$get(...)
Arguments
...
Nested indices (character or numeric) down the config list
Details
If no parameters are passed, returns the entire config_list
Returns
A subset of the list. If the item is NULL or missing, returns an error
Method get_dir_path()
Construct a directory path from the config object
Usage
Config$get_dir_path( dir_name, custom_version = NULL, fail_if_does_not_exist = FALSE )
Arguments
dir_name
Directory name
custom_version
(character, default NULL) A custom version that will be applied to this folder, rather than pulling from
config_list$versions[[dir]]
. Only applies to versioned folders.fail_if_does_not_exist
(logical, default FALSE) should this method return an error if the directory in question does not already exist?
Details
Works differently for versioned and non-versioned directories. See the class description for more information.
Returns
The full path to the directory
Method get_file_path()
Construct a file path from the config object
Usage
Config$get_file_path( dir_name, file_name, custom_version = NULL, fail_if_does_not_exist = FALSE )
Arguments
dir_name
Directory name
file_name
File name within that directory
custom_version
(character, default NULL) A custom version that will be applied to this folder, rather than pulling from
config_list$versions[[dir]]
. Only applies to versioned folders.fail_if_does_not_exist
(logical, default FALSE) should this method return an error if the directory in question does not already exist?
Details
Looks for the file path under:
config_list$directories[[dir_name]]$files[[file_name]]
Returns
The full path to the file Read a file based on the config
Method read()
Usage
Config$read(dir_name, file_name, ..., custom_version = NULL)
Arguments
dir_name
Directory name
file_name
File name within that directory
...
Optional file reading arguments to pass to
autoread()
custom_version
(character, default NULL) A custom version that will be applied to this folder, rather than pulling from
config_list$versions[[dir]]
. Only applies to versioned folders. If passed, this argument must always be explicitly named.
Returns
The object loaded by autoread()
Write an object to file based on the config
Method write()
Usage
Config$write(x, dir_name, file_name, ..., custom_version = NULL)
Arguments
x
Object to write
dir_name
Directory name
file_name
File name within that directory
...
Optional file writing arguments to pass to
autowrite()
custom_version
(character, default NULL) A custom version that will be applied to this folder, rather than pulling from
config_list$versions[[dir]]
. Only applies to versioned folders. If passed, this argument must always be explicitly named.
Returns
Invisibly passes TRUE if successful Convenience function: write the config list to a folder as 'config.yaml'
Method write_self()
Usage
Config$write_self(dir_name, ..., custom_version = NULL)
Arguments
dir_name
Directory name
...
Optional file writing arguments to pass to
autowrite()
custom_version
(character, default NULL) A custom version that will be applied to this folder, rather than pulling from
config_list$versions[[dir]]
. Only applies to versioned folders. If passed, this argument must always be explicitly named.
Returns
Invisibly passes TRUE if successful
Method clone()
The objects of this class are cloneable with this method.
Usage
Config$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.