addQueryTable: Import a table of data into a project data set as a new...

View source: R/importmisc.R

addQueryTableR Documentation

Import a table of data into a project data set as a new query.

Description

This function allows you to add a free-standing table to your project data. Unlike addScenario, it does not attempt to run the GCAM Model Interface; therefore, it is suitable for cases where the data has come from some other source, such as the output of a post-run analysis code.

Usage

addQueryTable(
  project,
  qdata,
  queryname,
  clobber = FALSE,
  transformation = NULL,
  saveProj = TRUE,
  strict.rundate = FALSE,
  ...
)

Arguments

project

The project data set to add the query to. This can be either a project data structure the name of a project data file.

qdata

Query data to add. This can be either a data frame or the name of a file containing the data in csv format.

queryname

The name to use for this query when it is stored in the project.

clobber

Flag: if TRUE, then the operation can replace a query in an existing scenario from the data set. If FALSE, then attempting to replace an existing query will cause the entire operation to fail.

transformation

Transformation function to the data after it has been cleaned up but before it has been added to the project.

saveProj

A flag to save the project to disk after data has been added. A user may want to avoid it if they are for instance calling this method several times and would prefer to save at the end. Users can always save at anytime by calling saveProject.

strict.rundate

Flag: if TRUE, then require that the run dates match in order to add queries to a scenario, and fail the entire operation if they don't. If FALSE, then ignore dates in the new data set.

...

Additional parameters to be passed to read.csv if qdata is a file name and therefore will get read from csv.

Details

The data to be read can be either a data frame or the name of a file containing the data. In the latter case, the data will be read using read.csv. The format of the table should be similar to the format of tables produced by the Model Interface. Namely:

  • There should be a "scenario" column with the scenario name in it. The date of the run, if any, will be stripped off.

  • There should be one or more columns that identify each data point, such as "region" or "sector". Column names will be converted to lower case.

  • There should be a "Units" column that gives the measurement unit for the data.

You can have multiple scenarios in a single table if you want. In that case the relevant data will be added to each scenario that appears in the "scenario" column. However, because the run date is stripped off, the scenarios must have distinct scenario names. Having multiple copies of the same scenario (i.e., the same scenario name, but different run dates) is not supported, and attempting to load such a table will result in a single query with duplicated rows.

The scenarios found will be added to the project data set supplied. This can be either the data set itself, or the name of a file containing the data set. Either way, the modified data set will be written back to the file it came from. If the attempt to add the query to any scenarios fails, then the function will throw an error and the project data will be unmodified.


JGCRI/rgcam documentation built on July 2, 2022, 10:20 a.m.