yaml_as_df: Read yaml input into data frame

View source: R/yaml-as-df.R

yaml_as_dfR Documentation

Read yaml input into data frame

Description

Read yaml input into data frame

Usage

yaml_as_df(path, quiet = FALSE, row_var = ".row")

Arguments

path

to the yaml source file.

quiet

logical; if TRUE, suppress messages.

row_var

character with length 1; column name where row names (from the yaml source) will be stored. If row_var already exists in the data frame, row names will be stored in row_var_N, where N is an integer such that new column with row names will not overwrite an existing column. Pass NULL to discard this column of row names.

Value

A tibble is created from yaml content and returned. By default, the first column in the data frame contains the outer names of the yaml source (see row_var argument and examples).

Prototyped tables

A prototyped table has one row identified as the prototype and defines the table column names as well as the required number of columns. This is similar behavior to what dplyr::tribble() does. Specify a prototype column name under ⁠SETUP__:⁠. You must provide names for all columns in the prototype. Other rows will inherit those names and you must enter a number of columns in other rows equal to the number found in the prototype. If a prototype row is used, then other rows do not need to be entered as (named) lists, but can be entered as arrays; they will be coerced to list and named according to the prototype.

Examples


path <- system.file("yaml", "table.yml", package = "pmtables")

yaml_as_df(path)

yaml_as_df(path, row_var = "name")

yaml_as_df(path, row_var = NULL)

# Example prototyped table
## Not run: 
file <- system.file("yaml", "prototype.yaml", package = "pmtables")
cat(readLines(file), sep = "\n")

## End(Not run)


metrumresearchgroup/pmtables documentation built on Oct. 27, 2024, 5:16 p.m.