Skip to contents

Global configuration

Most of the behaviour of dtrackr can be specified at the individual call level using the .headline and .messages glue specifications to define a format. Sometimes however this is annoying to do for all the stages in a flow chart and a global configuration of behaviour is desirable.

Naming conventions for groups

One of the areas where default behaviour may be undesirable is the naming of groups. The default setting combines the group name {.group} and the group value {.value} into a concatenated colon separated string as demonstrated below:

# these are the defaults
old = options(
  dtrackr.strata_glue="{.group}:{.value}",
  dtrackr.strata_sep="; "
)

survival::cgd %>%
  track() %>%
  group_by(treat) %>%
  comment() %>%
  group_by(sex,.add = TRUE) %>%
  comment(
    .messages = c(
    "{.count} patients",
    "{sprintf('%1.0f',.count/.total*100)}% of the total")) %>%
  ungroup() %>%
  flowchart()
%0 7:s->11 8:s->11 9:s->11 10:s->11 5:s->7 5:s->8 6:s->9 6:s->10 3:s->5 4:s->6 2:s->3 2:s->4 1:s->2 11 203 items7 treat:placebo; sex:female20 patients10% of the total8 treat:placebo; sex:male100 patients49% of the total9 treat:rIFN-g; sex:female15 patients7% of the total10 treat:rIFN-g; sex:male68 patients33% of the total5 stratify by treat, sex6 stratify by treat, sex3 treat:placebo120 items4 treat:rIFN-g83 items2 stratify by treat1 203 items
# reset options 
options(old)

In particular in situations like this where you are faceting on factors or strings, disposing of the group name may make this clearer. In the following example we only include the group value, force it to lower case, and use a comma to separate multiple facets. We have used manual override of the messages in the grouping stages, by providing a .messages parameter, to specify what we are faceting by in a more natural way:

# only include the group value in the description of the group
old = options(
  dtrackr.strata_glue="{tolower(.value)}",
  dtrackr.strata_sep=", "
)

survival::cgd %>%
  track() %>%
  group_by(treat, .messages = "case or control") %>%
  comment() %>%
  group_by(sex,
    .add = TRUE, 
    .messages = "by {tolower(.cols)}" #.cols contains a csv string of the grouping variables
  ) %>%
  comment(
    .messages = c(
    "{.count} patients",
    "{sprintf('%1.0f',.count/.total*100)}% of the total")) %>%
  ungroup() %>%
  flowchart()
%0 7:s->11 8:s->11 9:s->11 10:s->11 5:s->7 5:s->8 6:s->9 6:s->10 3:s->5 4:s->6 2:s->3 2:s->4 1:s->2 11 203 items7 placebo, female20 patients10% of the total8 placebo, male100 patients49% of the total9 rifn-g, female15 patients7% of the total10 rifn-g, male68 patients33% of the total5 by treat, sex6 by treat, sex3 placebo120 items4 rifn-g83 items2 case or control1 203 items
# reset options 
options(old)

N.B. this setting affects the “strata” label of the group, which in turn affects the flowchart branching. If this is not unique from one group to another strange behaviours will be observed.

Default text

With the group strata label defined you can set other defaults. In the flowchart above the “583 items” labels are generated by the default message setting, and the headings for the groups by the default headline setting. In this example we change these to alter the default text.

old = options(
  dtrackr.strata_glue="{tolower(.value)}",
  dtrackr.strata_sep=", ",
  dtrackr.default_message = "containing {.count} patients",
  dtrackr.default_headline = "subgroup: {.strata}"
)

survival::cgd %>%
  track() %>%
  group_by(
    treat,
    .messages = "case or control"
  ) %>%
  comment() %>%
  group_by(
    sex,
    .add = TRUE, 
    .messages = "by gender"
  ) %>%
  comment(
    .messages = c(
    "{.count} patients",
    "{sprintf('%1.0f',.count/.total*100)}% of the total")) %>%
  ungroup() %>%
  flowchart()
%0 7:s->11 8:s->11 9:s->11 10:s->11 5:s->7 5:s->8 6:s->9 6:s->10 3:s->5 4:s->6 2:s->3 2:s->4 1:s->2 11 subgroup: containing 203 patients7 subgroup: placebo, female20 patients10% of the total8 subgroup: placebo, male100 patients49% of the total9 subgroup: rifn-g, female15 patients7% of the total10 subgroup: rifn-g, male68 patients33% of the total5 by gender6 by gender3 subgroup: placebocontaining 120 patients4 subgroup: rifn-gcontaining 83 patients2 case or control1 subgroup: containing 203 patients
# N.b. this setting includes some unwanted headlines in the ungrouped stages of
# the flow chart. If a headline evaluates to "" then the headline is suppressed
# and we can get rid of unwanted headlines. An example of doing this is as
# follows:
# options(dtrackr.default_headline = "{ifelse(.strata != '', glue::glue('subgroup: {.strata}'), '')}")

# reset options 
options(old)

Subgroup count

Subgroup counts are a slightly neater way of doing this. Their default layout can be modified using dtrackr.default_count_subgroup.

old = options(
  dtrackr.default_headline = "{.strata}",
  dtrackr.default_count_subgroup = "{tolower(.name)}: {.count}/{.subtotal}"
)

survival::cgd %>%
  track() %>%
  group_by(
    treat,
    .messages = "case or control"
  ) %>%
  comment() %>%
  count_subgroup(
    sex
  ) %>%
  ungroup() %>%
  flowchart()
%0 5:s->7 6:s->7 3:s->5 4:s->6 2:s->3 2:s->4 1:s->2 7 203 items5 treat:placebomale: 100/120female: 20/1206 treat:rIFN-gmale: 68/83female: 15/833 treat:placebo120 items4 treat:rIFN-g83 items2 case or control1 203 items
# reset options 
options(old)

Exclusions

Elsewhere we discuss the possibility of capturing excluded items for debugging. This behaviour can be added to any pipeline with the capture_exclusions() function. Alternatively it can be globally enabled with the following option. Usual caveats about performance apply.

options(dtrackr.exclusions=TRUE)

Reporting exclusions which do nothing

Sometimes in a pipeline we have a exclusion criteria which is not triggered, or is not triggered for a particular subgroup. In this case the default is not to show the zero items that were excluded. However sometimes it is reassuring to know that an filter was applied even if it results in nothing:

options(dtrackr.show_zero_exclusions=FALSE)

Maximum groupings

In count_subgroup() and group_by() statements there can be a large number of items generated if a particular grouping variable has a lot of possible values. This can cause performance issues and legibility issues for the resulting graph and is usually a result of an interim stage of the data pipeline where grouping is used to do fine scale summarisation operation (e.g. a dataset %>% group_by(nearly_unique_id) %>% filter(row_number()==1) or a time-series where things need to be aggregated by date, and the data is quickly ungrouped (e.g. timeseries %>% group_by(date) %>% summarise(count = n())). The most number of groups that dtrackr will attempt to keep track of is configurable but defaults to 16:

options(dtrackr.max_supported_groupings = 16)

Verbose output

Various messages about what dtrackr is doing are produced but suppressed by default. They can be enabled with the following flag.

options(dtrackr.verbose=TRUE)