An S4 class to represent model/scenario planning horizon with intervals (year-steps)
Source:R/class-horizon.R
horizon.Rd
An S4 class to represent model/scenario planning horizon with intervals (year-steps)
Create a new object of class 'horizon'
Usage
newHorizon(
period = NULL,
intervals = NULL,
mid_is_end = FALSE,
mid_is_start = FALSE,
force_BY_interval_to_1_year = T,
desc = NULL,
name = NULL,
...
)
Arguments
- period
(optional) integer vector with a range or a sequence of period; will be arranged, gaps will be filled. If missing
- intervals
(optional) data.frame or integer vector. The data.frame must have `start`, `mid`, and `end` columns with modeled interval. The vector will be considered as lengths of each modeled interval in period.
- force_BY_interval_to_1_year
logical, if TRUE (default), the base-year (first) interval will be forced to one year.
- desc
character, a comment or description.
- ...
ignored
Slots
desc
character, a comment or a short description.
period
integer, a planning period defined as a sequence of years (arranged, without gaps) of the model planning (e.g. optimization) window. Data with years before or after the planning `period` can present in the model-objects and will be taken into account during interpolation of the model parameters. will be excluded from the the optimization.
intervals
data.frame with three columns, representing start, middle, and the end year of every interval.
Examples
newHorizon(2020:2050)
#> An object of class "horizon"
#> Slot "name":
#> character(0)
#>
#> Slot "desc":
#> character(0)
#>
#> Slot "period":
#> [1] 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034
#> [16] 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049
#> [31] 2050
#>
#> Slot "intervals":
#> start mid end
#> <int> <int> <int>
#> 1: 2020 2020 2020
#> 2: 2021 2021 2021
#> 3: 2022 2022 2022
#> 4: 2023 2023 2023
#> 5: 2024 2024 2024
#> 6: 2025 2025 2025
#> 7: 2026 2026 2026
#> 8: 2027 2027 2027
#> 9: 2028 2028 2028
#> 10: 2029 2029 2029
#> 11: 2030 2030 2030
#> 12: 2031 2031 2031
#> 13: 2032 2032 2032
#> 14: 2033 2033 2033
#> 15: 2034 2034 2034
#> 16: 2035 2035 2035
#> 17: 2036 2036 2036
#> 18: 2037 2037 2037
#> 19: 2038 2038 2038
#> 20: 2039 2039 2039
#> 21: 2040 2040 2040
#> 22: 2041 2041 2041
#> 23: 2042 2042 2042
#> 24: 2043 2043 2043
#> 25: 2044 2044 2044
#> 26: 2045 2045 2045
#> 27: 2046 2046 2046
#> 28: 2047 2047 2047
#> 29: 2048 2048 2048
#> 30: 2049 2049 2049
#> 31: 2050 2050 2050
#> start mid end
#>
newHorizon(2020:2030, desc = "One-year intervals")
#> An object of class "horizon"
#> Slot "name":
#> character(0)
#>
#> Slot "desc":
#> [1] "One-year intervals"
#>
#> Slot "period":
#> [1] 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030
#>
#> Slot "intervals":
#> start mid end
#> <int> <int> <int>
#> 1: 2020 2020 2020
#> 2: 2021 2021 2021
#> 3: 2022 2022 2022
#> 4: 2023 2023 2023
#> 5: 2024 2024 2024
#> 6: 2025 2025 2025
#> 7: 2026 2026 2026
#> 8: 2027 2027 2027
#> 9: 2028 2028 2028
#> 10: 2029 2029 2029
#> 11: 2030 2030 2030
#>
newHorizon(2020:2030, c(1, 2, 5, 10), desc = "Different length intervals")
#> An object of class "horizon"
#> Slot "name":
#> character(0)
#>
#> Slot "desc":
#> [1] "Different length intervals"
#>
#> Slot "period":
#> [1] 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030
#>
#> Slot "intervals":
#> start mid end
#> <num> <num> <num>
#> 1: 2020 2020 2020
#> 2: 2021 2021 2022
#> 3: 2023 2025 2027
#> 4: 2028 2028 2030
#>
newHorizon(2020:2035, c(1, 2, 5, 5, 5))
#> An object of class "horizon"
#> Slot "name":
#> character(0)
#>
#> Slot "desc":
#> character(0)
#>
#> Slot "period":
#> [1] 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034
#> [16] 2035
#>
#> Slot "intervals":
#> start mid end
#> <num> <num> <num>
#> 1: 2020 2020 2020
#> 2: 2021 2021 2022
#> 3: 2023 2025 2027
#> 4: 2028 2030 2032
#> 5: 2033 2033 2035
#>
newHorizon(2020:2050, c(1, 2, 5, 7, 1))
#> An object of class "horizon"
#> Slot "name":
#> character(0)
#>
#> Slot "desc":
#> character(0)
#>
#> Slot "period":
#> [1] 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034
#> [16] 2035
#>
#> Slot "intervals":
#> start mid end
#> <num> <num> <num>
#> 1: 2020 2020 2020
#> 2: 2021 2021 2022
#> 3: 2023 2025 2027
#> 4: 2028 2031 2034
#> 5: 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"
)
#> An object of class "horizon"
#> Slot "name":
#> character(0)
#>
#> Slot "desc":
#> [1] "Explicit assignment of intervals via data.frame"
#>
#> Slot "period":
#> [1] 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040
#>
#> Slot "intervals":
#> start mid end
#> <num> <num> <num>
#> 1: 2030 2030 2030
#> 2: 2031 2032 2033
#> 3: 2034 2037 2040
#>
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")
#> An object of class "horizon"
#> Slot "name":
#> character(0)
#>
#> Slot "desc":
#> [1] "The period will be trimmed to the scope of intervals"
#>
#> Slot "period":
#> [1] 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040
#>
#> Slot "intervals":
#> start mid end
#> <num> <num> <num>
#> 1: 2030 2030 2030
#> 2: 2031 2032 2033
#> 3: 2034 2037 2040
#>
newHorizon(2020:2050, c(3, 2, 5, 10),
desc = "Pay attention to the length of the first interval")
#> An object of class "horizon"
#> Slot "name":
#> character(0)
#>
#> Slot "desc":
#> [1] "Pay attention to the length of the first interval"
#>
#> Slot "period":
#> [1] 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034
#> [16] 2035 2036 2037 2038 2039
#>
#> Slot "intervals":
#> start mid end
#> <num> <num> <num>
#> 1: 2020 2020 2020
#> 2: 2021 2021 2022
#> 3: 2023 2023 2024
#> 4: 2025 2027 2029
#> 5: 2030 2034 2039
#>
newHorizon(period = 2020:2040,
intervals = data.frame(
start = c(2030, 2032, 2035),
mid = c(2031, 2033, 2037),
end = c(2032, 2034, 2040)))
#> An object of class "horizon"
#> Slot "name":
#> character(0)
#>
#> Slot "desc":
#> character(0)
#>
#> Slot "period":
#> [1] 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040
#>
#> Slot "intervals":
#> start mid end
#> <int> <int> <int>
#> 1: 2030 2030 2030
#> 2: 2031 2031 2032
#> 3: 2032 2033 2034
#> 4: 2035 2037 2040
#>