Skip to contents

section_div can be used to set or get the section divider for a table object produced by build_table(). When assigned in post-processing (section_div<-) the table can have a section divider after every row, each assigned independently. If assigning during layout creation, only split_rows_by() (and its related row-wise splits) and analyze() have a section_div parameter that will produce separators between split sections and data subgroups, respectively.

Usage

section_div(obj)

# S4 method for VTableTree
section_div(obj)

# S4 method for list
section_div(obj)

# S4 method for TableRow
section_div(obj)

section_div(obj, only_sep_sections = FALSE) <- value

# S4 method for VTableTree
section_div(obj, only_sep_sections = FALSE) <- value

# S4 method for list
section_div(obj, only_sep_sections = FALSE) <- value

# S4 method for TableRow
section_div(obj, only_sep_sections = FALSE) <- value

# S4 method for LabelRow
section_div(obj, only_sep_sections = FALSE) <- value

header_section_div(obj)

# S4 method for PreDataTableLayouts
header_section_div(obj)

# S4 method for VTableTree
header_section_div(obj)

header_section_div(obj) <- value

# S4 method for PreDataTableLayouts
header_section_div(obj) <- value

# S4 method for VTableTree
header_section_div(obj) <- value

top_level_section_div(obj)

# S4 method for PreDataTableLayouts
top_level_section_div(obj)

top_level_section_div(obj) <- value

# S4 method for PreDataTableLayouts
top_level_section_div(obj) <- value

Arguments

obj

(VTableTree)
table object. This can be of any class that inherits from VTableTree or TableRow/LabelRow.

only_sep_sections

(flag)
defaults to FALSE for section_div<-. Allows you to set the section divider only for sections that are splits or analyses if the number of values is less than the number of rows in the table. If TRUE, the section divider will be set for all rows of the table.

value

(character)
vector of single characters to use as section dividers. Each character is repeated such that all section dividers span the width of the table. Each character that is not NA_character_ will produce a trailing separator for each row of the table. value length should reflect the number of rows, or be between 1 and the number of splits/levels. See the Details section below for more information.

Value

The section divider string. Each line that does not have a trailing separator will have NA_character_ as section divider.

Details

Assigned value to section divider must be a character vector. If any value is NA_character_ the section divider will be absent for that row or section. When you want to only affect sections or splits, please use only_sep_sections or provide a shorter vector than the number of rows. Ideally, the length of the vector should be less than the number of splits with, eventually, the leaf-level, i.e. DataRow where analyze results are. Note that if only one value is inserted, only the first split will be affected. If only_sep_sections = TRUE, which is the default for section_div() produced from the table construction, the section divider will be set for all the splits and eventually analyses, but not for the header or each row of the table. This can be set with header_section_div in basic_table() or, eventually, with hsep in build_table(). If FALSE, the section divider will be set for all the rows of the table.

See also

basic_table() parameter header_section_div and top_level_section_div for global section dividers.

Examples

# Data
df <- data.frame(
  cat = c(
    "really long thing its so ", "long"
  ),
  value = c(6, 3, 10, 1)
)
fast_afun <- function(x) list("m" = rcell(mean(x), format = "xx."), "m/2" = max(x) / 2)

tbl <- basic_table() %>%
  split_rows_by("cat", section_div = "~") %>%
  analyze("value", afun = fast_afun, section_div = " ") %>%
  build_table(df)

# Getter
section_div(tbl)
#> [1] NA  " " "~" NA  " " "~"

# Setter
section_div(tbl) <- letters[seq_len(nrow(tbl))]
tbl
#>                             all obs
#> ———————————————————————————————————
#> really long thing its so           
#> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
#>   m                            8   
#> bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
#>   m/2                          5   
#> ccccccccccccccccccccccccccccccccccc
#> long                               
#> ddddddddddddddddddddddddddddddddddd
#>   m                            2   
#> eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
#>   m/2                         1.5  

# last letter can appear if there is another table
rbind(tbl, tbl)
#>                             all obs
#> ———————————————————————————————————
#> really long thing its so           
#> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
#>   m                            8   
#> bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
#>   m/2                          5   
#> ccccccccccccccccccccccccccccccccccc
#> long                               
#> ddddddddddddddddddddddddddddddddddd
#>   m                            2   
#> eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
#>   m/2                         1.5  
#> fffffffffffffffffffffffffffffffffff
#> really long thing its so           
#> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
#>   m                            8   
#> bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
#>   m/2                          5   
#> ccccccccccccccccccccccccccccccccccc
#> long                               
#> ddddddddddddddddddddddddddddddddddd
#>   m                            2   
#> eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
#>   m/2                         1.5  

# header_section_div
header_section_div(tbl) <- "+"
tbl
#>                             all obs
#> ———————————————————————————————————
#> +++++++++++++++++++++++++++++++++++
#> really long thing its so           
#> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
#>   m                            8   
#> bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
#>   m/2                          5   
#> ccccccccccccccccccccccccccccccccccc
#> long                               
#> ddddddddddddddddddddddddddddddddddd
#>   m                            2   
#> eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
#>   m/2                         1.5