Learn R Programming

gms (version 0.31.2)

writeSets: writeSets

Description

Function to write a set declaration in GAMS syntax given either a a character vector or a data.frame (latter to represent a mapping set)

Usage

writeSets(sets, file = NULL)

Value

set declaration in GAMS syntax

Arguments

sets

a list of sets where every set is another list consisting of three entries: name (set name as character), desc (set description as character) and items (set elements, either as character vector or data.frame)

file

Name of the file the set declarations should be written to. If NULL the result will just be returned by the function. The file must exist and contain a line of the form "##### R SECTION START (SETS) #####" followed by a line of the form ##### R SECTION END (SETS) ##### to indicate the part of the file that should be replaced with the set declaration!

Author

Jan Philipp Dietrich, Florian Humpenöder

Examples

Run this code
countries <- c("DEU", "FRA", "ENG", "ITA", "NLD", "POL")
map <- data.frame(region = rep(c("REG1","REG2"), 3), countries = countries)
sets <- list(list(name  = "countries", 
                  desc  = "list of countries", 
                  items = countries),
             list(name = "country2region",
                  desc = "mapping between countries and regions",
                  items = map))
 cat(writeSets(sets), sep="\n")

Run the code above in your browser using DataLab