Skip to content

Commit

Permalink
fixing minor docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Melkiades committed Nov 22, 2023
1 parent 8458e94 commit 1482855
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
27 changes: 11 additions & 16 deletions R/tree_accessors.R
Original file line number Diff line number Diff line change
Expand Up @@ -3205,7 +3205,6 @@ setMethod("trailing_section_div<-", "TableRow", function(obj, value) {
obj
})

# section_div getter from table object parts
#' @title Section dividers setter ang getter
#'
#' @description
Expand All @@ -3218,9 +3217,6 @@ setMethod("trailing_section_div<-", "TableRow", function(obj, value) {
#'
#' @param obj Table object. This can be of any class that inherits from `VTableTree`
#' or `TableRow`/`LabelRow`.
#' @param value character. Section divider 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.
#' @param only_sep_sections logical(1). Defaults to `FALSE` for `section_div<-`. It allows
#' 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
Expand All @@ -3232,11 +3228,17 @@ setMethod("trailing_section_div<-", "TableRow", function(obj, value) {
#' @seealso [basic_table()] parameter `header_section_div` for a global section divider.
#'
#' @details
#' If `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.
#' 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.
#'
#' @examples
#' # Data
Expand Down Expand Up @@ -3324,18 +3326,11 @@ setMethod("section_div<-", "VTableTree", function(obj, value, only_sep_sections

# Case where only separators or splits need to change externally
if (only_sep_sections && length(char_v) < nrow(obj)) {
if (length(char_v) == 1) {
char_v <- rep(char_v, max_tree_depth - 1) # -1 is the data row
}
# Case where char_v is longer than the max depth
char_v <- char_v[seq_len(min(max_tree_depth, length(char_v)))]
# Filling up with NAs the rest of the tree depth section div chr vector
missing_char_v_len <- max_tree_depth - length(char_v)
char_v <- c(char_v, rep(NA_character_, missing_char_v_len))
# char_v <- unlist(
# lapply(tree_depths, function(tree_depth_i) char_v[seq_len(tree_depth_i)]),
# use.names = FALSE
# )
}

# Retrieving if it is a contentRow (no need for labelrow to be visible in this case)
Expand Down
20 changes: 11 additions & 9 deletions man/section_div.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/testthat/test-accessors.R
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,17 @@ test_that("the split only setter works", {
split_rows_by("SEX", split_fun = drop_split_levels) %>%
analyze("AGE") %>%
build_table(DM)
tbl2 <- tbl
section_div(tbl) <- c("-", NA_character_)
section_div(tbl2) <- c("-")
expect_identical(
section_div(tbl)[seq_len(6)],
c(NA_character_, "-", NA_character_, "-", NA_character_, NA_character_)
)
expect_identical(
section_div(tbl),
section_div(tbl2)
)
})


Expand Down
2 changes: 1 addition & 1 deletion vignettes/dev-guide/dg_notes.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,4 @@ setMethod("section_div<-", "VTableTree", function(obj, value, only_sep_sections
})
```

`only_sep_sections` is a parameter that is used to change only the separators (between splits) and not the data rows. It is happening forcefully if set to `TRUE`, but it is automatically activated when `section_div(tbl) <- char_v` is a character vector of length `< nrow(tbl)`. Notice that the exception for `ContentRow` is activated by the switcher `is_content_table`. This is because content rows do not have visible label row. You see that in the main table structure change we have two blocks depending on `only_sep_sections`. If `TRUE` only the `VTableTree` are modified leading to only split section separators to be modified. Also consider looking at `section_div` getter and tests in `test-accessors.R` to have more insights on the structure.
`only_sep_sections` is a parameter that is used to change only the separators (between splits) and not the data rows. It is happening forcefully if set to `TRUE`, but it is automatically activated when `section_div(tbl) <- char_v` is a character vector of length `< nrow(tbl)`. Notice that the exception for `ContentRow` is activated by the switcher `is_content_table`. This is because content rows do not have visible label row. You see that in the main table structure change we have two blocks depending on `only_sep_sections`. If `TRUE` only the `VTableTree` are modified leading to only split section separators to be modified. Also consider looking at `section_div` getter and tests in `test-accessors.R` to have more insights on the structure. Also to understand exactly how this is bound to output, please check the result of `make_row_df()` for the column `trailing_sep`. Indeed, an alternative and iterative method is used by `make_row_df` to retrieve the information about the separators for each table row. Being it a trailing separator by definition, we added `header_section_div` as a function and a parameter of `basic_table`, so to possibly add an empty line after the header (e.g. `header_section_div(tbl) = " "`). This is not a trailing separator, but it is a separator that is added after the header. To close the circle, please check how `trailing_sep` and `header_section_div` is propagated and printed/used in `formatters::toString`.

0 comments on commit 1482855

Please sign in to comment.