Skip to content

using clin_group_by() with clin_auto_page(), if clin_auto_page drop is set to TRUE then running write_clindoc results in an error #91

Closed

Description

@PRawlinson-tfs

Dear clinify team,

Currently when using clin_group_by() with clin_auto_page(), if clin_auto_page drop is set to TRUE then running write_clindoc results in an error “Error in x$data[rows, columns, drop = FALSE] : subscript out of bounds”. Using these options together would be ideal for many by-visit continuous summaries like Vital Signs or Labs, where the Parameter is a subtitle and we want to keep all summary stats (n, mean, sd, median, min, max) for a visit together on a page. For example:

ct <- clintable(df) |>
clin_group_by("PARAM") |>
clin_auto_page("AVISITN", drop=TRUE)

write_clindoc(
x = ct,
file =”table.docx"
)

Is there a known work-around for this? Or perhaps I’ve just missed something?

Many thanks for your help!

Activity

  1. mstackhouse commented on Oct 17, 2025

    @mstackhouse
    Member

    Would you be able to prepare this as a reprex?

    I think this could be possible with this example. The challenge is when you toss in other features like captions. The more you want to customize pagination, the less you can rely on word to do it.

    With clin_group_by(), you can rely on the natural flow of pages and it's more like you're just stacking several pages together. Once a caption is in place, you need the flextable to end on each individual page, because the table in word won't apply the caption on the bottom until it hits the last row (of the table in word itself, not of the page).

  2. PRawlinson-tfs commented on Oct 20, 2025

    @PRawlinson-tfs
    Author

    Sure, thanks! If you run this code do you get the error?

    df <- data.frame(PARAM=c('Parameter: SYSBP', 'Parameter: SYSBP', 'Parameter: SYSBP', 'Parameter: SYSBP', 'Parameter: SYSBP',
    'Parameter: SYSBP', 'Parameter: SYSBP', 'Parameter: SYSBP', 'Parameter: SYSBP', 'Parameter: SYSBP',
    'Parameter: DIABP', 'Parameter: DIABP', 'Parameter: DIABP', 'Parameter: DIABP', 'Parameter: DIABP',
    'Parameter: DIABP', 'Parameter: DIABP', 'Parameter: DIABP', 'Parameter: DIABP', 'Parameter: DIABP'),
    AVISITN=c(3,3,3,3,3,
    4,4,4,4,4,
    3,3,3,3,3,
    4,4,4,4,4),
    col1=c('DAY 1', 'n', 'Mean (SD)', 'Median', 'Min, Max',
    'DAY 5', 'n', 'Mean (SD)', 'Median', 'Min, Max',
    'DAY 1', 'n', 'Mean (SD)', 'Median', 'Min, Max',
    'DAY 5', 'n', 'Mean (SD)', 'Median', 'Min, Max'),
    stat_1=c('', '90', '127.6 (15.53)', '126.0', '85, 175',
    '', '87', '124.0 (13.79)', '124.0', '80, 150',
    '', '90', '88.8 (14.72)', '89.0', '65, 109',
    '', '87', '85.9 (13.10', '86.0', '61, 109'),
    stat_2=c('', '80', '124.1 (14.81)', '124.5.0', '85, 161',
    '', '85', '126.5 (15.14)', '125.0', '92, 175',
    '', '80', '86.7 (14.72)', '87.2', '63, 101',
    '', '85', '87.9 (13.10', '86.0', '61, 111')

    )

    library(clinify)

    ct <- clintable(df) |>
    clin_group_by("PARAM") |>
    clin_auto_page("AVISITN", drop=TRUE)

    write_clindoc(
    x = ct,
    file ='table.docx'
    )

  3. mstackhouse commented on Nov 4, 2026

    @mstackhouse
    Member

    This is fixed as of clinify 0.4.0 (now on CRAN). Your example with clin_group_by("PARAM") |> clin_auto_page("AVISITN", drop = TRUE) now writes without the "subscript out of bounds" error. It came from pagination losing the table's configuration once the page_by column was dropped. Thanks for the reprex!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions