Learn R Programming

tidytlg (version 0.1.5)

tlgsetup: Setup data to support the specified column type

Description

tlgsetup is useful for pre-processing total columns and columns composed of other columns. tlgsetup is called internally by generate_results() and can be run manually for custom tables.

Usage

tlgsetup(
  df,
  var,
  column_metadata_file = NULL,
  column_metadata = NULL,
  tbltype = NULL
)

Value

dataframe with observations added to support the column type as well as the factor variable colnbr which is used as our new column summary variable. Regardless of if a coldef exists in data, the column will exist in the table.

Arguments

df

dataframe of records for analysis

var

character vector that identifies the numeric column/treatment variable

column_metadata_file

A file containing the column metadata. Read in with readxl::read_excel(). If a column_metadata dataframe is passed in too, this is ignored.

column_metadata

A dataframe containing the column metadata. This will be used in place of column_metadata_file.

tbltype

A value used to subset the column_metadata, both this and the file requirements are needed to bind the data to the table.

Examples

Run this code
df <-
  tibble::tribble(
  ~TRT01AN, ~USUBJID,
  0,        "A",
 54,       "B",
 81,       "C"
)

tlgsetup(df, "TRT01AN", column_metadata = column_metadata)

# Using a dataframe of column metadata
column_metadata <-
  tibble::tribble(
    ~tbltype, ~coldef, ~decode,                ~span1,
    "type1",  "0",     "Placebo",              "",
    "type1",  "54",    "Low Dose",             "Xanomeline",
    "type1",  "81",    "High Dose",            "Xanomeline",
    "type1",  "54+81", "Total Xanomeline",     ""
  )

tlgsetup(df, "TRT01AN", column_metadata = column_metadata)

Run the code above in your browser using DataLab