Learn R Programming

fz (version 1.2.0)

fzo: fzo Function

Description

Reads and parses output file(s) according to the model's output commands. Each matched directory is processed independently; the results are combined into a single list or data frame.

Usage

fzo(output_path, model)

Value

Named list or data frame of parsed output values. An output entry may resolve to a vector (list) - e.g. a time series or spectrum - which is stored per case unmodified (no flattening, padding, or truncation).

Arguments

output_path

Path or glob pattern matching one or more output directories. Subdirectories within matched directories are not processed.

model

Model definition dict or alias string.

Output extraction methods

Each entry of the model's output list is a string describing how to extract that value from the case directory. Besides the default shell command (optionally marked "bash://..."), funz-fz >= 1.2 supports shell-free extractors, portable on Windows without a bash install:

  • "python://<expr>" - a Python expression evaluated in the case directory with helpers such as grep(), read(), lines(), json_file(), csv_file(), hdf5_file() and the re/json/math/ statistics/np/pd modules.

  • "jq://<filter> <file>" - JSON extraction via the jq executable.

  • "yq://<filter> <file>" - YAML/JSON/XML/TOML extraction via mikefarah/yq.

  • "xpath://<expr> <file>" - XML extraction via xmllint --xpath.

The python://, jq://, yq:// and xpath:// forms preserve list results as vectors; a plain shell command simplifies a single-element result to a scalar.

Examples

Run this code
# \donttest{
if (fz_available()) {
  out_dir <- file.path(tempdir(), "P=2,V=11.2")
  dir.create(out_dir, recursive = TRUE)
  writeLines("result = 42", file.path(out_dir, "output.txt"))

  model <- list(
    varprefix = "$", delim = "{}", formulaprefix = "@", commentline = "#",
    output = list(result = "grep 'result' output.txt | cut -d= -f2")
  )

  values <- fzo(out_dir, model)
}
# }

Run the code above in your browser using DataLab