Read yaml input into data frame
yaml_as_df(path, quiet = FALSE, row_var = ".row")
to the yaml source file.
logical; if TRUE
, suppress messages.
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.
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).
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.
path <- system.file("yaml", "table.yml", package = "pmtables")
yaml_as_df(path)
#> # A tibble: 4 × 6
#> .row study description population subjects endpoints
#> <chr> <chr> <chr> <chr> <int> <chr>
#> 1 row1 12-DEMO-222 "single ascending dose PK stu… healthy s… 12 PK
#> 2 row2 11-DEMO-221 "multiple ascending dose PK s… healthy s… 30 PK
#> 3 row3 13-DEMO-311 "phase2a study in patients" patients … 60 PK, E2
#> 4 row4 18-DEMO-001 "pivitol phase 3 registration… patients … 240 PK, E2, …
yaml_as_df(path, row_var = "name")
#> # A tibble: 4 × 6
#> name study description population subjects endpoints
#> <chr> <chr> <chr> <chr> <int> <chr>
#> 1 row1 12-DEMO-222 "single ascending dose PK stu… healthy s… 12 PK
#> 2 row2 11-DEMO-221 "multiple ascending dose PK s… healthy s… 30 PK
#> 3 row3 13-DEMO-311 "phase2a study in patients" patients … 60 PK, E2
#> 4 row4 18-DEMO-001 "pivitol phase 3 registration… patients … 240 PK, E2, …
yaml_as_df(path, row_var = NULL)
#> # A tibble: 4 × 5
#> study description population subjects endpoints
#> <chr> <chr> <chr> <int> <chr>
#> 1 12-DEMO-222 "single ascending dose PK study" healthy s… 12 PK
#> 2 11-DEMO-221 "multiple ascending dose PK study" healthy s… 30 PK
#> 3 13-DEMO-311 "phase2a study in patients" patients … 60 PK, E2
#> 4 18-DEMO-001 "pivitol phase 3 registration trial… patients … 240 PK, E2, …
# Example prototyped table
if (FALSE) { # \dontrun{
file <- system.file("yaml", "prototype.yaml", package = "pmtables")
cat(readLines(file), sep = "\n")
} # }