This function processes an R extraction script template specification in a spreadsheet format and produce the corresponding R extraction script template file (an R Markdown file with the extension .Rxs.Rmd)

rxs_fromSpecifications(
  x = NULL,
  outputFile = NULL,
  outputPath = NULL,
  outputFilenamePattern = NULL,
  localBackup = NULL,
  yamlMetadata = NULL,
  rxsRootName = metabefor::opts$get(rxsRootName),
  preventOverwriting = FALSE,
  errorOnFailingValidation = FALSE,
  silent = metabefor::opts$get("silent"),
  instructionHeadingLevel = 3,
  graphTheme = list(c("fontname", "Arial", "node")),
  ignoreModules = FALSE,
  returnFullObject = TRUE,
  gs_url = NULL,
  localFile = NULL
)

Arguments

x

A Google Sheets URL (make sure it's viewable by anybody with the link!) or either a character value with a valid path to a spreadsheet (.xlsx) with the worksheets, or a named list of character strings each pointing to a .csv file with the relevant worksheet, where the names of each character value represent the names of the worksheets contained in each file.

outputFile

When not working with modules, the path to a directory and file where the Rxs template will be stored. If NULL, the produced Rxs template (or the full object, depending on returnFullObject) is returned visibly.

outputPath, outputFilenamePattern

If NULL, the produced Rxs templates are returned (visibly) in a list (or the full object is, depending on returnFullObject). If not NULL, outputPath has to be a valid path where the Rxs templates will be written to, and outputFilenamePattern has to be a valid character value (i.e. a text string) containing %s in the position where the module identifier will be inserted in the filenames.

localBackup

If not NULL, either a path to a single .xlsx file to save a local backup spreadsheet to, or a named list with character values, where each name is the name of a worksheet (e.g. entities, valueTemplates, definitions, and instructions), and each named value is the path to store the corresponding worksheets will be stored as .csv file.

yamlMetadata

Optionally, override the YAML metadata set in the template, specifically, by providing a named list containing one or more of title, author, and date as character values. If provided, these will override the default values in the Rmd file that is the Rxs template.

rxsRootName

The name of the root element

preventOverwriting

Whether to prevent accidental overwriting of the extraction templates.

errorOnFailingValidation

Whether to throw an error when validation failed or not. If FALSE, the validation log is shown in the rendered output; if TRUE rendering is aborted by an error that shows the log.

silent

Whether to be silent or chatty.

instructionHeadingLevel

The top-most heading level for the instructions.

graphTheme

The graph theme to use.

ignoreModules

Optionally, you can ignore modules specified in the Rxs specification spreadsheet by setting ignoreModules to TRUE.

returnFullObject

Whether to return the full object or just the template.

gs_url

DEPRECATED - please use x instead! A Google Sheets URL (make sure it's viewable by anybody with the link!).

localFile

DEPRECATED - please use x instead! When reading from a local file, pass either a character value with a valid path to a spreadsheet (.xlsx) with the worksheets, or a named list of character strings each pointing to a .csv file with the relevant worksheet, where the names of each character value represent the names of the worksheets contained in each file.

Value

Either a full object, containing the template and other products, or just the template.

Examples

### Create a temporary directory
tmpPath <- tempfile(pattern="rxsDir");
dir.create(tmpPath);

### This can be run if you have an internet connection
if (interactive()) {
  gs_url <-
    paste0("https://docs.google.com/spreadsheets/d/",
           "1wM7HGrqVs-6KV0XeeyEeMIz-IRfF-llMXHJUD73N7Dk");
  rxsSpec <-
    rxs_fromSpecifications(
      x = gs_url,
      outputPath = tmpPath,
      outputFilenamePattern = "rxsSpec-%s.rxs.rmd"
    );
  cat(tmpPath);
}

### This can always be run, as it used a local file
rxsSpecSpreadsheetPath <-
  system.file(package="metabefor",
              "extdata",
              "Rxs_minimal_example_2.xlsx");
rxsSpec_fromLocal <-
    rxs_fromSpecifications(
      x = rxsSpecSpreadsheetPath,
      outputPath = tmpPath,
      outputFilenamePattern = "rxsSpec-%s.rxs.rmd"
    );
#> Error in metabefor::read_spreadsheet(x = x, localBackup = localBackup,     silent = silent): To read Excel spreadsheets (`.xlsx`), the {readxl} package has to be installed. You can install it with:
#> 
#>   install.packages('readxl');