Skip to contents

This function reads a YAML file containing specifications, handles potential reading errors, and extracts specific information based on a provided path.

Usage

seasonder_readYAMLSpecs(file_path, path = rlang::zap())

Arguments

file_path

A string. The path to the YAML file.

path

A character vector. Represents the path within the YAML file to access the desired information. For example, to access fields of version V2 of the header, the path would be c("header", "versions", "V2").

Value

A list. The information extracted from the YAML file based on the provided path.

Details

This function provides built-in error handling which aborts execution and logs detailed error messages in case of:

  • File not found.

  • Error in reading the YAML content.

  • The read YAML content is not a list.

  • No data found for the provided path in the YAML content.

Errors generated are of class "seasonder_read_yaml_file_error". For logging and aborting, this function uses seasonder_logAndAbort.

See also

read_yaml for the underlying YAML reading.

pluck for the data extraction mechanism used.

Examples

# Example: Read the CS header specifications (version V1) from the default specs file
specs_path <- seasonder_defaultSpecsFilePath("CS")
result <- seasonder_readYAMLSpecs(specs_path, c("header", "V1"))
str(result)
#> List of 3
#>  $ nCsFileVersion:List of 3
#>   ..$ type     : chr "SInt16"
#>   ..$ qc_fun   : chr "qc_check_range"
#>   ..$ qc_params:List of 3
#>   .. ..$ min          : int 1
#>   .. ..$ max          : int 32
#>   .. ..$ expected_type: chr "integer"
#>  $ nDateTime     :List of 3
#>   ..$ type     : chr "UInt32"
#>   ..$ qc_fun   : chr "qc_check_unsigned"
#>   ..$ qc_params:List of 1
#>   .. ..$ expected_type: chr "numeric"
#>  $ nV1Extent     :List of 3
#>   ..$ type     : chr "SInt32"
#>   ..$ qc_fun   : chr "qc_check_type"
#>   ..$ qc_params:List of 1
#>   .. ..$ expected_type: chr "integer"