R/load_dct_dir.R

Defines functions load_dct_dir

Documented in load_dct_dir

#' @rdname load_dct_specs
#' @export
load_dct_dir <- function(path,
                         recursive = TRUE,
                         extension = "\\.rock|\\.dct\\.yaml|\\.yaml|\\.yml",
                         regex,
                         dctContainer = "dct",
                         headingLevel = 2,
                         delimiterRegEx = "^---$",
                         ignoreOddDelimiters = FALSE,
                         encoding="UTF-8",
                         sortDecreasing = FALSE,
                         silent=TRUE) {

  if (!dir.exists(path)) {
    stop("Directory '",
         path,
         "' does not exist!");
  }

  if (missing(regex)) {
    regex <- paste0("^(.*)\\.", extension, "$");
  }

  ###--------------------------------------------------------------------------
  ### Load the YAML fragments containing the DCT specifications
  ###--------------------------------------------------------------------------

  dctSpecs <-
    yum::load_and_simplify_dir(
      path = path,
      recursive = recursive,
      fileRegexes = regex,
      select = dctContainer,
      delimiterRegEx = delimiterRegEx,
      ignoreOddDelimiters = ignoreOddDelimiters,
      encoding = encoding,
      silent = silent
    );

  ###--------------------------------------------------------------------------
  ### Parse DCT specifications and return result
  ###--------------------------------------------------------------------------

  dctSpecs <- lapply(
    dctSpecs,
    function(x) {
      class(x) <- c("psyverse_dct", class(x));
      return(x);
    }
  );

  res <-
    parse_dct_specs(dctSpecs,
                    headingLevel=headingLevel,
                    sortDecreasing=sortDecreasing);

  return(res);

}

Try the psyverse package in your browser

Any scripts or data that you put into this service are public.

psyverse documentation built on March 7, 2023, 8:31 p.m.