Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hsep propagation fix #789

Merged
merged 5 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Whitespace is not trimmed when rendering tables with `as_html`.
* Started deprecation cycle for `col_fnotes_here` to be replaced with `col_footnotes`.
* Exported `section_div` methods now have a dedicated documentation page that is visible to users.
* When tables are exported as `txt`, they preserve the horizontal separator of the table.

## rtables 0.6.5
### New Features
Expand Down
3 changes: 2 additions & 1 deletion R/argument_conventions.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ NULL
#' @param hsep character(1). Set of character(s) to be repeated as the separator
#' between the header and body of the table when rendered as text. Defaults to
#' a connected horizontal line (unicode 2014) in locals that use a UTF
#' charset, and to `-` elsewhere (with a once per session warning).
#' charset, and to `-` elsewhere (with a once per session warning). See
#' [formatters::set_default_hsep()] for further information.
#' @param indent_size numeric(1). Number of spaces to use per indent level.
#' Defaults to 2
#' @param section_div character(1). String which should be repeated as a section
Expand Down
6 changes: 2 additions & 4 deletions R/tt_toString.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ NULL

#' Convert an `rtable` object to a string
#'
#' @inheritParams formatters::toString
#' @inheritParams gen_args
#' @inherit formatters::toString
#' @param x table object
#' @param widths widths of row.name and columns
#' @param col_gap gap between columns
#' @param hsep character to create line separator
#' @exportMethod toString
#'
#' @return a string representation of \code{x} as it appears when printed.
Expand Down Expand Up @@ -340,6 +337,7 @@ setMethod(
prov_footer = prov_footer(obj),
table_inset = table_inset(obj),
header_section_div = header_section_div(obj),
horizontal_sep = horizontal_sep(obj),
indent_size = indent_size
)
}
Expand Down
3 changes: 2 additions & 1 deletion man/build_table.Rd

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

8 changes: 5 additions & 3 deletions man/export_as_pdf.Rd

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

3 changes: 2 additions & 1 deletion man/gen_args.Rd

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

4 changes: 2 additions & 2 deletions man/paginate.Rd

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

3 changes: 2 additions & 1 deletion man/rtable.Rd

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

3 changes: 2 additions & 1 deletion man/tabclasses.Rd

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

16 changes: 11 additions & 5 deletions man/table_shell.Rd

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

18 changes: 12 additions & 6 deletions man/tostring.Rd

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

4 changes: 2 additions & 2 deletions man/tt_to_flextable.Rd

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

17 changes: 17 additions & 0 deletions tests/testthat/test-printing.R
Original file line number Diff line number Diff line change
Expand Up @@ -739,3 +739,20 @@ test_that("Separators and wrapping work together with getter and setters", {
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
)
})

test_that("horizontal separator is propagated from table to print and export", {
# GitHub error #778
lyt <- basic_table() %>%
split_cols_by("Species") %>%
analyze("Sepal.Length", afun = function(x) {
list(
"mean (sd)" = rcell(c(mean(x), sd(x)), format = "xx.xx (xx.xx)"),
"range" = diff(range(x))
)
})

tbl <- build_table(lyt, iris, hsep = "~")
tostring_tbl <- strsplit(toString(tbl), "\n")[[1]]
export_txt_tbl <- strsplit(export_as_txt(tbl), "\n")[[1]]
expect_identical(tostring_tbl, export_txt_tbl)
})