Skip to contents

The function creates a new object of class 'horizon' that represents the planning horizon of the model/scenario.

Usage

newHorizon(
  period = NULL,
  intervals = NULL,
  mid_is_end = FALSE,
  mid_is_start = FALSE,
  force_BY_interval_to_1_year = TRUE,
  base_year = NULL,
  desc = NULL,
  name = NULL,
  misc = NULL
)

# S4 method for class 'horizon'
update(object, ..., warn_nodata = TRUE)

# S4 method for class 'config'
setHorizon(obj, period, ...)

# S4 method for class 'config'
update(object, ..., warn_nodata = TRUE)

Arguments

period

(optional) integer vector with a range or a sequence of years to define the full period of the model/scenario. If not provided, the range of 'intervals' will be used.

intervals

(optional) either data.frame or integer vector. The data.frame must have start, mid, and end columns with modeled interval. An optional label column gives each milestone a display name; it is filled from mid when absent, must be unique, and is presentation only – the model key for a period stays the integer mid. See year_label(). The vector will be considered as lengths of each modeled interval in period.

mid_is_end

logical, if TRUE, the mid-year will be set to the end of the interval.

mid_is_start

logical, if TRUE, the mid-year will be set to the start of the interval.

force_BY_interval_to_1_year

logical, if TRUE (default), the base-year (first) interval will be forced to one year.

base_year

a single integer year, or NULL (the default) for a horizon every year of which is optimised. The marked year is GIVEN rather than decided: it is interpolated as any other year and what it holds can be carried forward as stock, but it is not passed to the solver – its own solution comes from a separate solve. Milestones before it are historical and leave the model altogether, remaining interpolation anchors only. Must name a milestone of this horizon, and cannot be its last. See solve_base_year().

desc

character. Description of the horizon object, for own references.

name

character. Name of the horizon object. Used to distinguish between different horizons in the model or scenario, including the automatic creation of the folder name for the model/scenario scripts.

misc

list. Any additional data or information to store in the object.

object

the horizon or config object to update.

...

named slots with new values.

warn_nodata

logical; warn when the update is called with no data.

obj

the config object, for the setHorizon method.

horizon

a new horizon object to be set.

Value

An object of class 'horizon'

Examples

newHorizon(2020:2050)
#> <horizon> (unnamed)
#> 
#> intervals  [31 x 4]
#>     start  mid  end label
#>  1:  2020 2020 2020  2020
#>  2:  2021 2021 2021  2021
#>  3:  2022 2022 2022  2022
#>  4:  2023 2023 2023  2023
#>  5:  2024 2024 2024  2024
#> ---                      
#> 27:  2046 2046 2046  2046
#> 28:  2047 2047 2047  2047
#> 29:  2048 2048 2048  2048
#> 30:  2049 2049 2049  2049
#> 31:  2050 2050 2050  2050
newHorizon(2020:2030, desc = "One-year intervals")
#> <horizon> (unnamed) -- One-year intervals
#> 
#> intervals  [11 x 4]
#>     start  mid  end label
#>  1:  2020 2020 2020  2020
#>  2:  2021 2021 2021  2021
#>  3:  2022 2022 2022  2022
#>  4:  2023 2023 2023  2023
#>  5:  2024 2024 2024  2024
#>  6:  2025 2025 2025  2025
#>  7:  2026 2026 2026  2026
#>  8:  2027 2027 2027  2027
#>  9:  2028 2028 2028  2028
#> 10:  2029 2029 2029  2029
#> 11:  2030 2030 2030  2030
newHorizon(2020:2030, c(1, 2, 5, 10), desc = "Different length intervals")
#> <horizon> (unnamed) -- Different length intervals
#> 
#> intervals  [4 x 4]
#>    start  mid  end label
#> 1:  2020 2020 2020  2020
#> 2:  2021 2021 2022  2021
#> 3:  2023 2025 2027  2025
#> 4:  2028 2028 2030  2028
newHorizon(2020:2035, c(1, 2, 5, 5, 5))
#> <horizon> (unnamed)
#> 
#> intervals  [5 x 4]
#>    start  mid  end label
#> 1:  2020 2020 2020  2020
#> 2:  2021 2021 2022  2021
#> 3:  2023 2025 2027  2025
#> 4:  2028 2030 2032  2030
#> 5:  2033 2033 2035  2033
newHorizon(2020:2050, c(1, 2, 5, 7, 1))
#> <horizon> (unnamed)
#> 
#> intervals  [5 x 4]
#>    start  mid  end label
#> 1:  2020 2020 2020  2020
#> 2:  2021 2021 2022  2021
#> 3:  2023 2025 2027  2025
#> 4:  2028 2031 2034  2031
#> 5:  2035 2035 2035  2035

newHorizon(intervals = data.frame(
  start = c(2030, 2031, 2034),
  mid =   c(2030, 2032, 2037),
  end =   c(2030, 2033, 2040)),
  desc = "Explicit assignment of intervals via data.frame"
  )
#> <horizon> (unnamed) -- Explicit assignment of intervals via data.frame
#> 
#> intervals  [3 x 4]
#>    start  mid  end label
#> 1:  2030 2030 2030  2030
#> 2:  2031 2032 2033  2032
#> 3:  2034 2037 2040  2037

newHorizon(period = 2020:2050,
           intervals = data.frame(
             start = c(2030, 2031, 2034),
             mid =   c(2030, 2032, 2037),
             end =   c(2030, 2033, 2040)),
             desc = "The period will be trimmed to the scope of intervals")
#> <horizon> (unnamed) -- The period will be trimmed to the scope of intervals
#> 
#> intervals  [3 x 4]
#>    start  mid  end label
#> 1:  2030 2030 2030  2030
#> 2:  2031 2032 2033  2032
#> 3:  2034 2037 2040  2037

newHorizon(2020:2050, c(3, 2, 5, 10),
           desc = "Pay attention to the length of the first interval")
#> <horizon> (unnamed) -- Pay attention to the length of the first interval
#> 
#> intervals  [5 x 4]
#>    start  mid  end label
#> 1:  2020 2020 2020  2020
#> 2:  2021 2021 2022  2021
#> 3:  2023 2023 2024  2023
#> 4:  2025 2027 2029  2027
#> 5:  2030 2034 2039  2034

# Explicit display labels; `mid` remains the model key
newHorizon(intervals = data.frame(
  start = c(2025, 2030),
  mid   = c(2025, 2030),
  end   = c(2029, 2034),
  label = c("FY2025-26", "FY2030-31")))
#> <horizon> (unnamed)
#> 
#> intervals  [3 x 4]
#>    start  mid  end     label
#> 1:  2025 2025 2025 FY2025-26
#> 2:  2026 2026 2029      2026
#> 3:  2030 2030 2034 FY2030-31

newHorizon(period = 2020:2040,
           intervals = data.frame(
             start = c(2030, 2032, 2035),
             mid =   c(2031, 2033, 2037),
             end =   c(2032, 2034, 2040)))
#> <horizon> (unnamed)
#> 
#> intervals  [4 x 4]
#>    start  mid  end label
#> 1:  2030 2030 2030  2030
#> 2:  2031 2031 2032  2031
#> 3:  2032 2033 2034  2033
#> 4:  2035 2037 2040  2037