getDataForAllScens: Get and aggregate data from an rdf file(s)

View source: R/getDataFromRdf.R

getDataForAllScensR Documentation

Get and aggregate data from an rdf file(s)

Description

getDataForAllScens() gets slot data from multiple rdf files and/or multiple scenarios, aggregates it, and saves it as a data.frame. The slot data can be aggregated in multiple ways (see slot_agg_list).

Usage

getDataForAllScens(
  scenFolders,
  scenNames,
  slotAggList,
  scenPath,
  oFile = NULL,
  retFile = NULL,
  findAllSlots = TRUE
)

Arguments

scenFolders

A string vector containing the folder names (scenarios) that the rdf files are saved in.

scenNames

A string vector containing the scenario names. This should be the same length as scenFolders. The scenario names are used as attributes to the data in the Scenario column.

slotAggList

The slot aggregation list. Either an object of class slot_agg_list or a "special" list with the keyword "all". If, it is a slot_agg_list, see that documentation for how to control the aggregation methods used in this function. If all of the slots in an entire rdf are desired, use a list of lists with each entry containing an rdf file and the keyword "all" for the slots, e.g., list(list(rdf = 'KeySlots.rdf',slots = 'all')). If this option is used, the function will return raw monthly, or annual data, i.e., no aggregation methods will be applied to the data in the rdf file.

scenPath

An absolute or relative path to the folder containing scenFolders.

oFile

If not NULL, then an absolute or relative path with the file name of the location the table will be saved to. Valid file types are .csv, .txt, or .feather.

retFile

Deprecated. Data are always returned invisibly.

findAllSlots

Boolean; if TRUE (default), then the function will abort if it cannot find a particular slot. If FALSE, then the function will continue, even if a slot cannot be found. If a slot is not found, then the function will return -99 for the Trace, Year, and Value.

Value

A data.frame returned invisibly.

See Also

slot_agg_list()

Examples

# get a specified set of slots and apply some aggregation method to them
# get the data from two scenarios
scenFolders <- c('ISM1988_2014,2007Dems,IG,Most', 
  'ISM1988_2014,2007Dems,IG,2002') 
# slotAggTable.csv lists the slots to obtain, and the aggregation method to 
# apply to them
slotAggList <- slot_agg_list(
  system.file('extdata','SlotAggTable.csv',package = 'RWDataPlyr')
)
scenPath <- system.file('extdata','Scenario/',package = 'RWDataPlyr')
# expect Deprecated warning
testthat::expect_warning(
  keyData <- getDataForAllScens(
    scenFolders, 
    scenNames = scenFolders, 
    slotAggList = slotAggList, 
    scenPath = scenPath
  )
)

# get all of the data from the KeySlots rdf file
scenFolders <- scenFolders[1] # only one scenario
slotAggList <- list(list(rdf = 'KeySlots.rdf', slots = 'all'))
# will return monthly data for all slots in KeySlots.rdf
# expect Deprecated warning
testthat::expect_warning(
  allData <- getDataForAllScens(
    scenFolders, 
    scenNames = scenFolders, 
    slotAggList = slotAggList, 
    scenPath = scenPath
  )
)


BoulderCodeHub/RWDataPlyr documentation built on May 8, 2023, 3:55 a.m.