Skip to contents

[Experimental] Provides tools for obtaining a tidy version of a summarised_result object.

Usage

tidySummarisedResult(
  result,
  splitGroup = TRUE,
  splitStrata = TRUE,
  splitAdditional = TRUE,
  settingsColumns = colnames(settings(result)),
  pivotEstimatesBy = "estimate_name",
  nameStyle = NULL
)

Arguments

result

A summarised_result.

splitGroup

If TRUE it will split the group name-level column pair.

splitStrata

If TRUE it will split the group name-level column pair.

splitAdditional

If TRUE it will split the group name-level column pair.

settingsColumns

Settings to be added as columns, by default all settings will be added. If NULL or empty character vector, no settings will be added.

pivotEstimatesBy

Names from which pivot wider the estimate values. If NULL the table will not be pivotted.

nameStyle

Name style (glue package specifications) to customise names when pivotting estimates. If NULL standard tidyr::pivot_wider formatting will be used.

Value

A tibble.

Examples

{
result <- mockSummarisedResult()

result |> tidySummarisedResult()

result |>
  tidySummarisedResult(
    settingsColumns =character(),
    pivotEstimatesBy = c("variable_name", "variable_level", "estimate_name")
  )

result |>
  tidySummarisedResult(
    settingsColumns =character(),
    pivotEstimatesBy = c("variable_name", "variable_level", "estimate_name"),
    nameStyle = "{estimate_name}_{variable_name}_{variable_level}"
  )
}
#> # A tibble: 18 × 12
#>    result_id cdm_name cohort_name age_group sex     `count_number subjects`
#>        <int> <chr>    <chr>       <chr>     <chr>                     <int>
#>  1         1 mock     cohort1     overall   overall                 1282760
#>  2         1 mock     cohort1     <40       Male                    2792266
#>  3         1 mock     cohort1     >=40      Male                    8204054
#>  4         1 mock     cohort1     <40       Female                  3945057
#>  5         1 mock     cohort1     >=40      Female                  8876022
#>  6         1 mock     cohort1     overall   Male                    5942974
#>  7         1 mock     cohort1     overall   Female                  2463778
#>  8         1 mock     cohort1     <40       overall                 3757580
#>  9         1 mock     cohort1     >=40      overall                 1368529
#> 10         1 mock     cohort2     overall   overall                  986021
#> 11         1 mock     cohort2     <40       Male                    6423973
#> 12         1 mock     cohort2     >=40      Male                    8174897
#> 13         1 mock     cohort2     <40       Female                  1567231
#> 14         1 mock     cohort2     >=40      Female                  5118733
#> 15         1 mock     cohort2     overall   Male                    7105515
#> 16         1 mock     cohort2     overall   Female                  3634426
#> 17         1 mock     cohort2     <40       overall                 6686055
#> 18         1 mock     cohort2     >=40      overall                 7204168
#> # ℹ 6 more variables: mean_age <dbl>, sd_age <dbl>,
#> #   count_Medications_Amoxiciline <int>,
#> #   percentage_Medications_Amoxiciline <dbl>,
#> #   count_Medications_Ibuprofen <int>, percentage_Medications_Ibuprofen <dbl>