| Title: | Utilities for the piam-verse |
|---|---|
| Description: | This package contains utilities and helpers needed in various piam libraries. |
| Authors: | Falk Benke [aut, cre], Alex K. Hagen [aut] (ORCID: <https://orcid.org/0000-0003-4793-8664>), Christof Schötz [aut] |
| Maintainer: | Falk Benke <[email protected]> |
| License: | LGPL-3 |
| Version: | 0.2.1 |
| Built: | 2026-09-18 16:40:02 UTC |
| Source: | https://github.com/pik-piam/piamutils |
A helper to analyze two magpie objects for differences.
compareMagpieObject(x, y, tol = 0)compareMagpieObject(x, y, tol = 0)
x |
a magpie object or a string referring to a file that can be read in as a mapgie object |
y |
a magpie object or a string referring to a file that can be read in as a mapgie object |
tol |
optional value between 0 and 1 to restrict value differences between the two magpie objects to be listed, a data entry must exceed 'tol' percent of the maximum value difference observed in the data to be listed |
Falk Benke
The function can take a multiple of input formats. It replaces "|+|", "|++|", "|+++|", ... by "|" in variable names and in this "deletes" the "plus-notation".
deletePlus(mif, writemif = FALSE)deletePlus(mif, writemif = FALSE)
mif |
A path to a mif-file (might be created by confGDX2MIF), a magpie object containing reporting, a quitte object, or a character vector or factor of variable names. |
writemif |
A single truth value. Only used when mif is a file path. Should the new mif with the adjusted names be saved? If yes the new name will have the suffix "_withoutPlus.mif". |
If mif is a file path and writemif is FALSE, a MAgPIE
object. If mif is not a file path the result is the object mif with
replaced variable names.
deletePlus(c( "ab|cd", # "ab|cd" "de|+|fgh", # "de|fgh" "i|j|++|k|l|++++|mno|p", # "i|j|k|l|mno|p" "++|q+|+r|+p+|u+v|+", # "++|q+|+r|+p+|u+v|+" "w|+|+|x")) # "w|x"deletePlus(c( "ab|cd", # "ab|cd" "de|+|fgh", # "de|fgh" "i|j|++|k|l|++++|mno|p", # "i|j|k|l|mno|p" "++|q+|+r|+p+|u+v|+", # "++|q+|+r|+p+|u+v|+" "w|+|+|x")) # "w|x"
A wrapper around system.file to make sure that the correct paths are returned when working with devtools::load_all() during development.
getSystemFile(..., package = "base", mustWork = FALSE)getSystemFile(..., package = "base", mustWork = FALSE)
... |
character vectors, specifying subdirectory and file(s) within some package |
package |
a character string with the name of a single package |
mustWork |
if TRUE, an error is given if there are no matching files |
Modify Variable Names
modifyVariableNames(x, modify, writeMifSuffix = NULL, ...)modifyVariableNames(x, modify, writeMifSuffix = NULL, ...)
x |
A path to a mif-file (might be created by confGDX2MIF), a magpie object containing reporting, a quitte object, or a character vector or factor of variable names. |
modify |
A function that modifies a character vector. |
writeMifSuffix |
|
... |
Further arguments for the modify function. |
If x is a file path and writeMifSuffix is NULL,
a MAgPIE object. If x is not a file path the result is the object
x with replaced variable names.
niceround returns human-readable string for big and small numbers Show everything before the dot and at least 'digits' significant digits For a data.frame, convert all numeric columns
niceround(x, digits = 3)niceround(x, digits = 3)
x |
either a vector or list of numbers, or a dateframe |
digits |
number of significant digits that are definitely kept |
Read data for a given symbol from a gdx file and return it as a dataframe using gamstransfer::readGDX
readGdxToDf(symbolName, pathToGdx, ...)readGdxToDf(symbolName, pathToGdx, ...)
symbolName |
The name of a symbol to be extracted from gdx. |
pathToGdx |
Path to a gdx file. |
... |
Additional arguments passed to gamstransfer::readGDX. |
A data frame with data about symbolName from the given gdx file.
Falk Benke
Substitute Placeholders in Variable Names.
substitutePlaceholder(x, writeMifSuffix = NULL, substitutions = c(. = "$dot$"))substitutePlaceholder(x, writeMifSuffix = NULL, substitutions = c(. = "$dot$"))
x |
A path to a mif-file (might be created by confGDX2MIF), a quitte object, or a character vector or factor of variable names. |
writeMifSuffix |
|
substitutions |
A named character vector of placeholders with replacements as names. |
If x is not a file path the result is the object x with
replaced variable names.
substitutePlaceholder(c( "3$dot$5", # "3.5" "3$dot5", # "3$dot5" "3.5", # "3.5" "$dot$dot$dot$dot$dot$")) # ".dot.dot."substitutePlaceholder(c( "3$dot$5", # "3.5" "3$dot5", # "3$dot5" "3.5", # "3.5" "$dot$dot$dot$dot$dot$")) # ".dot.dot."
Export Data Frame / Data Table to GDX Parameter and save to file based on gamstransfer package
writeDfToGDXparameter( ddata, gdxFileName, paramName, domainCols = NULL, valueCol = "value", description = "" )writeDfToGDXparameter( ddata, gdxFileName, paramName, domainCols = NULL, valueCol = "value", description = "" )
ddata |
data.frame or data.table |
gdxFileName |
Output file name incl. path (e.g., "pXX_someName.gdx") |
paramName |
Name of the GAMS parameter in GDX |
domainCols |
Optional vector of column names for domains. If NULL, defaults to all columns except 'valueCol'. |
valueCol |
Name of the numerical value column (default: "value") |
description |
Optional description for the parameter (default: "") |
'NULL', invisibly. Called for the side effect of writing 'gdxFileName'.
Alex K. Hagen