load_config: Load a YAML config file as 'scdrake_list'.

View source: R/config_load.R

load_configR Documentation

Load a YAML config file as scdrake_list.

Description

load_config() loads a single YAML file as a scdrake_list().

load_pipeline_config(), load_single_samples_configs(), and load_integration_configs() load a specific config group (pipeline, single-sample, integration) and return a named list of scdrake_lists.

Usage

load_config(
  yaml_file,
  other_variables = NULL,
  eval_code = TRUE,
  verbose = getOption("scdrake_verbose")
)

load_pipeline_config(
  dir = getOption("scdrake_pipeline_config_dir"),
  process = TRUE,
  ...
)

load_single_sample_configs(
  dir = getOption("scdrake_single_sample_config_dir"),
  cfg_pipeline = NULL,
  process = TRUE,
  ...
)

load_integration_configs(
  dir = getOption("scdrake_integration_config_dir"),
  cfg_pipeline = NULL,
  process = TRUE,
  ...
)

Arguments

yaml_file

A character scalar: path to YAML file.

other_variables

A list of variables in whose environment the yaml_file will be evaluated, see details below.

eval_code

A logical scalar: if TRUE, evaluate code for parameters in the yaml_file whose value starts with !code .

verbose

A logical scalar: if TRUE, be verbose. The default value is obtained from getOption("scdrake_verbose").

dir

A character scalar:

  • For load_pipeline_config(): a path to directory with pipeline.yaml file.

  • For load_single_sample_config(): a path to directory with ⁠00_main.yaml⁠, ⁠01_input_qc.yaml⁠, ⁠02_norm_clustering.yaml⁠, cluster_markers.yaml, and contrasts.yaml files.

  • For load_integration_config(): a path to directory with ⁠00_main.yaml⁠, ⁠01_integration.yaml⁠, ⁠02_int_clustering.yaml⁠, cluster_markers.yaml, and contrasts.yaml files.

process

A logical scalar: if TRUE, internally process the loaded config. This is always needed prior to sending the config to functions generating a drake plan, but in some cases could be useful to see the raw config.

...

Passed to load_config().

cfg_pipeline

A scdrake_list object: pipeline config (see load_pipeline_config()) obtained from pipeline.yaml file located in pipeline config directory.

Details

Except load_pipeline_config(), you can refer to variables from pipeline.yaml and ⁠00_main.yaml⁠ configs inside individual configs. For example, you can use ⁠CLUSTER_SC3_N_CORES: !code DRAKE_N_JOBS⁠ in ⁠02_norm_clustering.yaml⁠.

Value

A scdrake_list() of parameters loaded from the YAML file, or a named list of such lists.

Evaluating code inside YAML files

All parameters in the yaml_file whose value starts with !code will be evaluated as R code. Those can reference other parameters in the yaml_file, or variables in the individual lists of the other_variables list. Note that you cannot reference other !code parameters as their are not already evaluated during the runtime.

An example YAML file:

VAR_1: 5
VAR_2: !code VAR_1 + 5
VAR_3: "apple"
VAR_4:
  VAR_4_1: !code str_upper(VAR_3)
VAR_5:
  - VAR_5_1:
      a: !code VAR_1 + 1
    VAR_5_2:
      b: !code 1:10
VAR_6: !code VAR_2 + 10
  • VAR_2 will be 10.

  • VAR_4_1 will be "APPLE".

  • VAR_5_1 will be 6.

  • VAR_5_2 will be a numeric vector.

  • VAR_6 will throw error, because VAR_2 will still be unevaluated, so R will try to add 10 to the character scalar.

Note that VAR_5 contains a single named list, and this structure is used quite often in scdrake configs. You have to keep an eye on the proper indentation :)

Examples

# If a scdrake project is in the current working directory.
## Not run: 
cfg_1 <- load_config("config/pipeline.yaml")
cfg_2 <- load_config(
  "config/single_sample/00_main.yaml",
  other_variables = cfg_1
)

## End(Not run)

## Not run: 
pipeline_config <- load_pipeline_config()
pipeline_config_other <- load_pipeline_config("some/other/dir/config.yaml")

## End(Not run)

## Not run: 
single_sample_config <- load_single_sample_configs()
single_sample_config_other <- load_single_sample_configs("some/other/dir")

## End(Not run)

## Not run: 
integration_config <- load_integration_configs()
single_sample_config_other <- load_integration_configs("some/other/dir")

## End(Not run)


bioinfocz/scdrake documentation built on Sept. 19, 2024, 4:43 p.m.