Package 'piamutils'

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

Help Index


compareMagpieObject

Description

A helper to analyze two magpie objects for differences.

Usage

compareMagpieObject(x, y, tol = 0)

Arguments

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

Author(s)

Falk Benke


Delete "+" in Variable Names. Optionally Save in File with Suffix "_withoutPlus"

Description

The function can take a multiple of input formats. It replaces "|+|", "|++|", "|+++|", ... by "|" in variable names and in this "deletes" the "plus-notation".

Usage

deletePlus(mif, writemif = FALSE)

Arguments

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".

Value

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.

Examples

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"

Find the path to R System Files for a given R library

Description

A wrapper around system.file to make sure that the correct paths are returned when working with devtools::load_all() during development.

Usage

getSystemFile(..., package = "base", mustWork = FALSE)

Arguments

...

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

Description

Modify Variable Names

Usage

modifyVariableNames(x, modify, writeMifSuffix = NULL, ...)

Arguments

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

NULL or a suffix for the file name if the result should be written as a mif-file.

...

Further arguments for the modify function.

Value

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

Description

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

Usage

niceround(x, digits = 3)

Arguments

x

either a vector or list of numbers, or a dateframe

digits

number of significant digits that are definitely kept


readGdxToDf

Description

Read data for a given symbol from a gdx file and return it as a dataframe using gamstransfer::readGDX

Usage

readGdxToDf(symbolName, pathToGdx, ...)

Arguments

symbolName

The name of a symbol to be extracted from gdx.

pathToGdx

Path to a gdx file.

...

Additional arguments passed to gamstransfer::readGDX.

Value

A data frame with data about symbolName from the given gdx file.

Author(s)

Falk Benke


Substitute Placeholders in Variable Names.

Description

Substitute Placeholders in Variable Names.

Usage

substitutePlaceholder(x, writeMifSuffix = NULL, substitutions = c(. = "$dot$"))

Arguments

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

NULL or a suffix for the filename if the result should be written as a mif-file.

substitutions

A named character vector of placeholders with replacements as names.

Value

If x is not a file path the result is the object x with replaced variable names.

Examples

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

Description

Export Data Frame / Data Table to GDX Parameter and save to file based on gamstransfer package

Usage

writeDfToGDXparameter(
  ddata,
  gdxFileName,
  paramName,
  domainCols = NULL,
  valueCol = "value",
  description = ""
)

Arguments

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: "")

Value

'NULL', invisibly. Called for the side effect of writing 'gdxFileName'.

Author(s)

Alex K. Hagen