rtables_access {tern} | R Documentation |
Helper functions for accessing information from rtables
Description
These are a couple of functions that help with accessing the data in rtables
objects.
Currently these work for occurrence tables, which are defined as having a count as the first
element and a fraction as the second element in each cell.
Usage
h_row_first_values(table_row, col_names = NULL, col_indices = NULL)
h_row_counts(table_row, col_names = NULL, col_indices = NULL)
h_row_fractions(table_row, col_names = NULL, col_indices = NULL)
h_col_counts(table, col_names = NULL, col_indices = NULL)
h_content_first_row(table)
is_leaf_table(table)
check_names_indices(table_row, col_names = NULL, col_indices = NULL)
Arguments
table_row |
( |
col_names |
( |
col_indices |
( |
table |
( |
Value
-
h_row_first_values()
returns avector
of numeric values.
-
h_row_counts()
returns avector
of numeric values.
-
h_row_fractions()
returns avector
of proportions.
-
h_col_counts()
returns avector
of column counts.
-
h_content_first_row()
returns a row from anrtables
table.
-
is_leaf_table()
returns alogical
value indicating whether current table is a leaf.
-
check_names_indices
returns column indices.
Functions
-
h_row_first_values()
: Helper function to extract the first values from each content cell and from specified columns in aTableRow
. Defaults to all columns. -
h_row_counts()
: Helper function that extracts row values and checks if they are convertible to integers (integerish
values). -
h_row_fractions()
: Helper function to extract fractions from specified columns in aTableRow
. More specifically it extracts the second values from each content cell and checks it is a fraction. -
h_col_counts()
: Helper function to extract column counts from specified columns in a table. -
h_content_first_row()
: Helper function to get first row of content table of current table. -
is_leaf_table()
: Helper function which says whether current table is a leaf in the tree. -
check_names_indices()
: Internal helper function that tests standard inputs for column indices.
See Also
prune_occurrences for usage of these functions.
Examples
tbl <- basic_table() %>%
split_cols_by("ARM") %>%
split_rows_by("RACE") %>%
analyze("AGE", function(x) {
list(
"mean (sd)" = rcell(c(mean(x), sd(x)), format = "xx.x (xx.x)"),
"n" = length(x),
"frac" = rcell(c(0.1, 0.1), format = "xx (xx)")
)
}) %>%
build_table(tern_ex_adsl) %>%
prune_table()
tree_row_elem <- collect_leaves(tbl[2, ])[[1]]
result <- max(h_row_first_values(tree_row_elem))
result
# Row counts (integer values)
# h_row_counts(tree_row_elem) # Fails because there are no integers
# Using values with integers
tree_row_elem <- collect_leaves(tbl[3, ])[[1]]
result <- h_row_counts(tree_row_elem)
# result
# Row fractions
tree_row_elem <- collect_leaves(tbl[4, ])[[1]]
h_row_fractions(tree_row_elem)