Skip to contents

Helper function for funtions that accept a quant_pairs argument. Validates/formats the given pairs, or infers the quantile pairs from forecast data.

Usage

parse_quant_pairs(quant_pairs, df, allow_empty = FALSE)

Arguments

quant_pairs

A list of pairs, a single pair, or NULL

df

A forecast data frame

allow_empty

If FALSE, an error will be raised when no quantile pairs can be inferred. If TRUE, an empty list will be returned silently. Defaults to FALSE.

Value

A list of pairs, either taken from quant_pairs or inferred from df

Examples

# infer from forecast
casteval:::parse_quant_pairs(
  NULL,
  data.frame(time=1, val_q10=2, val_q25=3, val_50=4, val_q75=5, val_q90=6)
)
#> [[1]]
#> [1] 10 90
#> 
#> [[2]]
#> [1] 25 75
#> 

# single pair
casteval:::parse_quant_pairs(
  c(2.5,97.5),
  data.frame(time=1, val=1)
)
#> [[1]]
#> [1]  2.5 97.5
#> 

# multiple pairs
casteval:::parse_quant_pairs(
  list(c(2.5,97.5), c(25,75)),
  data.frame(time=1, val=1)
)
#> [[1]]
#> [1]  2.5 97.5
#> 
#> [[2]]
#> [1] 25 75
#> 

# allow empty
casteval:::parse_quant_pairs(
  NULL,
  data.frame(time=1:3, val_q50=4:6),
  allow_empty=TRUE
)
#> list()

casteval:::parse_quant_pairs(
  list(),
  data.frame(time=1, val=1),
  allow_empty=TRUE
)
#> list()