RWDataPlyr (version 0.6.2)

rdf_to_rwtbl: Convert an rdf to a tibble

Description

rdf_to_rwtbl() converts an rdf list to a tibble.

rdf_to_rwtbl2() converts an rdf file into a tibble, but is faster than rdf_to_rwtbl() since it uses c++. It also reads the rdf file in, while rdf_to_rwtbl() needs an rdf object.

Usage

rdf_to_rwtbl(rdf, scenario = NULL, keep_cols = FALSE, add_ym = TRUE)

rdf_to_rwtbl2(file, scenario = NA_character_, keep_cols = FALSE, add_ym = TRUE)

Arguments

rdf

An rdf object (from read_rdf()).

scenario

An optional parameter, that if it is not NULL or NA (default) will be added to the tibble as another variable. Coerced to a character if it is not already a character.

keep_cols

Either boolean, or a character vector of column names to keep in the returned tibble. The values of keep_cols work as follows:

  • FALSE (default) only includes the defaults columns: Timestep, TraceNumber, ObjectSlot, and Value. Scenario is also returned if scenario is specified.

  • TRUE, all columns are returned.

  • A character vector, e.g., c("ObjectName", "Units"), allows the user to include other columns that are not always required, in addition to the "default" set of columns. If any of the values in keep_cols are not found, a warning will post, but all other columns will be returned.

add_ym

Boolean that controls whether or not Year and Month columns are added to the returned tibble. If TRUE (default), they will be added, and if FALSE they will not be added. They are constructed from the dates in the Timestep column.

file

The relative or absolute rdf filename.

Value

A tbl_df with additional attributes from the rdf object.

Details

The rdf object is converted to a data frame, and then converted to a tibble::tibble(). All of the meta entries in the rdf object are stored as attributes in the returned tibble. These attributes are: mrm_config_name, owner, description, create_date, and n_traces.

If the rdf contains a scalar slot(s), the scalar slot value(s) will be repeated for every timestep.

See Also

read_rdf()

Examples

Run this code
# NOT RUN {
rdftbl <- rdf_to_rwtbl(keyRdf)
# same as previous, except you do not want "Year" and "Month" columns
rdftbl <- rdf_to_rwtbl(keyRdf, add_ym = FALSE)
# but you do want to keep the object name seperately:
rdftbl <- rdf_to_rwtbl(keyRdf, add_ym = FALSE, keep_cols = "Object")
rdftbl <- rdf_to_rwtbl(sysRdf, scenario = "ISM1988_2014,2007Dems,IG,2002")

# rdf_to_rwtbl2 wants a file path instead of an rdf object
rdfPath <- system.file(
  "extdata/Scenario/ISM1988_2014,2007Dems,IG,Most/KeySlots.rdf", 
  package = "RWDataPlyr"
)
rdftbl <- rdf_to_rwtbl2(rdfPath)

# }

Run the code above in your browser using DataCamp Workspace