
Cheat sheet: Get started
Source:vignettes/articles/cheatsheet-get-started.Rmd
cheatsheet-get-started.RmdFrom a project folder to a solved model: regions and time, five bricks, one model, one solve -- and the sheet to open next
PDF, A4, one page · energyRt 0.91.5.9019 (dev) · 2026-12-05Install
pak::pkg_install(c("optimal2050/energyRt",
"glpsol"))
library(energyRt)
en_check_dependencies() # what is installed
glpsol brings the GLPK solver: enough for small models.From project to result
| project |
create_project() once, open_project() later |
| ↓ brick |
newCommodity(), newTechnology(), ... |
| ↓ repository |
newRepository(), add()
|
| ↓ model |
newModel(): bricks + regions, calendar, horizon |
| ↓ scenario |
interpolate_model(): the problem |
| ↓ run |
solve_scenario(): one solve, one solver |
| ↓ results |
getData(), autoplot(), report()
|
1 · A project
create_project("hello_project")
Once: a folder with its stores and a registry, opened. Models, scenarios and runs are kept there; a later session calls
open_project().2 · Regions and time
REGIONS <- "R1"
CALENDAR <- calendars$annual
HELLO_HORIZON <- newHorizon(
name = "HELLO_HORIZON",
period = 2025:2040,
intervals = c(1, 5, 10),
mid_is_end = TRUE
)
| regions | names, or a geoscale with a map: newModel(geoscale = ) -- Spatial resolution
|
| calendar | time within a year: calendars$annual 1 timeslice, s4_hp3 12, d365_h24 8760 -- Time resolution
|
| horizon | the milestone years and the years each stands for |
Decided before any brick: they set the size of the problem and the region and timeslice columns of every table.
3 · Bricks
GAS <- newCommodity(
name = "GAS",
timeframe = "ANNUAL",
unit = "PJ"
)
ELC <- newCommodity(
name = "ELC",
timeframe = "ANNUAL",
unit = "PJ"
)
SUP_GAS <- newSupply(
name = "SUP_GAS",
commodity = "GAS",
unit = "PJ",
supply = data.frame(cost = 6) # MEUR/PJ
)
gas_efficiency <- data.frame(
comm = "GAS",
cinp2use = 0.55
)
EGAS <- newTechnology(
name = "EGAS",
desc = "Gas power plant",
input = list(comm = "GAS"),
output = list(comm = "ELC"),
ceff = gas_efficiency,
invcost = data.frame(invcost = 900),
cap2act = 31.536, # PJ per GW-year
olife = 25L
)
DEM_ELC <- newDemand(
name = "DEM_ELC",
commodity = "ELC",
unit = "PJ",
demand = data.frame(demand = 50)
)
One fuel, one plant (900 MEUR/GW), one demand. The object is named as its
name.draw() shows any brick before anything is solvedOther bricks: newStorage(), newTrade(), newImport(), newExport(), newWeather(), newConstraint(), newTax(), newSubsidy(). Names: a commodity is a bare mnemonic (GAS); a process carries its type and commodity (SUP_GAS, DEM_ELC, STG_ELC, TRD_); power plants are E + fuel (EGAS).
4 · Repository and model
HELLO_REPOSITORY <- newRepository(
name = "HELLO_REPOSITORY",
GAS, ELC, SUP_GAS, EGAS, DEM_ELC
)
HELLO <- newModel(
name = "HELLO",
data = HELLO_REPOSITORY,
region = REGIONS,
calendar = CALENDAR,
horizon = HELLO_HORIZON,
discount = 0.05
)
The repository is a box of bricks, reusable; the model binds it to the regions, the calendar and the horizon.
5 · Solve
BASE <- solve_model(
object = HELLO,
name = "BASE",
solver = solver_options$glpk
)
One call: interpolate, write, solve, read, save. The stages one by one, runs and scenarios: Workflow & scenarios.
6 · Read and plot
getData(BASE, name = "vTechCap",
merge = TRUE)
# A tibble: 3 × 6 scenario name tech region year value <chr> <chr> <chr> <chr> <int> <dbl> 1 BASE vTechCap EGAS R1 2025 1.59 2 BASE vTechCap EGAS R1 2030 1.59 3 BASE vTechCap EGAS R1 2040 1.59
autoplot(BASE, type = "capacity")
autoplot() reads the solved scenario- Every result is a table:
getData()by variable name,getMix()for a commodity's mix,findData()to search;levcost()andreport()build on them. - Names:
vTechCap,vTechNewCap,vTechOut,vTechInp,vObjective-- all on the Variables sheet.
Adding a brick
EWIN <- newTechnology(
name = "EWIN",
output = list(comm = "ELC"),
af = list(af.up = 0.35),
invcost = data.frame(invcost = 1300),
cap2act = 31.536,
olife = 25L
)
HELLO_WIND <- add(HELLO, EWIN)
WIND <- solve_model(
object = HELLO_WIND,
name = "WIND",
solver = solver_options$glpk
)
getData(WIND, name = "vTechCap",
merge = TRUE, year = 2040)
# A tibble: 1 × 6 scenario name tech region year value <chr> <chr> <chr> <chr> <int> <dbl> 1 WIND vTechCap EWIN R1 2040 4.53
The first model is untouched; the two scenarios can be compared (
compare_scenarios()). update() changes a brick.Further sheets
| Declare | Model bricks · Technology · Supply & demand · Storage · Trade · Vintages & clusters |
| Assemble | Time resolution · Spatial resolution · Custom constraints · Levelized cost |
| Run | Workflow & scenarios · Backends & solvers · Diagnostics |
| Read | Reading results · Visualization · Reports |
| Under the hood | Variables · Parameters · Equations |
A complete example country: build_topia(), on the sheet TOPIA, the example model; the Results and Visualization sheets read it. Larger models are solved by multimod (solver_options$mm_highs).
Pitfalls
- Create the project before the first brick: without one, scenarios are written to a temporary folder and are lost with the session.
- State the units.
cap2actties capacity to activity: 31.536 PJ, or 8760 GWh, per GW-year. - Limits and demands (
ava.up,demand) are per timeslice of the commodity'stimeframe, not per year. - A demand nothing can meet makes the model infeasible -- see Diagnostics.