diff --git a/NEWS.md b/NEWS.md index 222229f34..afb220b1f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/argument_conventions.R b/R/argument_conventions.R index 70c6cd964..bcc7c1bd5 100644 --- a/R/argument_conventions.R +++ b/R/argument_conventions.R @@ -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 diff --git a/R/tt_toString.R b/R/tt_toString.R index bbbcd6987..2f46d5510 100644 --- a/R/tt_toString.R +++ b/R/tt_toString.R @@ -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. @@ -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 ) } diff --git a/man/build_table.Rd b/man/build_table.Rd index 3e1cc9528..353a35a4d 100644 --- a/man/build_table.Rd +++ b/man/build_table.Rd @@ -38,7 +38,8 @@ displayed during printing.} \item{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 \code{-} elsewhere (with a once per session warning).} +charset, and to \code{-} elsewhere (with a once per session warning). See +\code{\link[formatters:default_horizontal_sep]{formatters::set_default_hsep()}} for further information.} \item{\dots}{currently ignored.} } diff --git a/man/export_as_pdf.Rd b/man/export_as_pdf.Rd index 7af03060a..df34fc3c8 100644 --- a/man/export_as_pdf.Rd +++ b/man/export_as_pdf.Rd @@ -78,7 +78,9 @@ this is calculated automatically based on the specified page size). \code{NULL} indicates no horizontal pagination should occur.} \item{hsep}{character(1). Characters to repeat to create -header/body separator line.} +header/body separator line. If \code{NULL}, the object value will be +used. If \code{" "}, an empty separator will be printed. Check \code{\link[formatters:default_hsep]{default_hsep()}} +for more information.} \item{indent_size}{numeric(1). Indent size in characters. Ignored when \code{x} is already a \code{MatrixPrintForm} object in favor of information @@ -87,9 +89,9 @@ there.} \item{tf_wrap}{logical(1). Should the texts for title, subtitle, and footnotes be wrapped?} -\item{max_width}{integer(1), character(1) or NULL. Width that title +\item{max_width}{integer(1), character(1) or \code{NULL}. Width that title and footer (including footnotes) materials should be -word-wrapped to. If NULL, it is set to the current print width +word-wrapped to. If \code{NULL}, it is set to the current print width of the session (\code{getOption("width")}). If set to \code{"auto"}, the width of the table (plus any table inset) is used. Ignored completely if \code{tf_wrap} is \code{FALSE}.} diff --git a/man/gen_args.Rd b/man/gen_args.Rd index 53ce36782..a965d0de3 100644 --- a/man/gen_args.Rd +++ b/man/gen_args.Rd @@ -89,7 +89,8 @@ when forcing pagination between the children of this split/table} \item{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 \code{-} elsewhere (with a once per session warning).} +charset, and to \code{-} elsewhere (with a once per session warning). See +\code{\link[formatters:default_horizontal_sep]{formatters::set_default_hsep()}} for further information.} \item{indent_size}{numeric(1). Number of spaces to use per indent level. Defaults to 2} diff --git a/man/paginate.Rd b/man/paginate.Rd index c4bd27c4b..92bed8aed 100644 --- a/man/paginate.Rd +++ b/man/paginate.Rd @@ -49,9 +49,9 @@ considerations. Defaults to none.} \item{colwidths}{numeric vector. Column widths for use with vertical pagination.} -\item{max_width}{integer(1), character(1) or NULL. Width that title +\item{max_width}{integer(1), character(1) or \code{NULL}. Width that title and footer (including footnotes) materials should be -word-wrapped to. If NULL, it is set to the current print width +word-wrapped to. If \code{NULL}, it is set to the current print width of the session (\code{getOption("width")}). If set to \code{"auto"}, the width of the table (plus any table inset) is used. Ignored completely if \code{tf_wrap} is \code{FALSE}.} diff --git a/man/rtable.Rd b/man/rtable.Rd index 94c82b6e0..5a8e402ab 100644 --- a/man/rtable.Rd +++ b/man/rtable.Rd @@ -24,7 +24,8 @@ format labels.} \item{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 \code{-} elsewhere (with a once per session warning).} +charset, and to \code{-} elsewhere (with a once per session warning). See +\code{\link[formatters:default_horizontal_sep]{formatters::set_default_hsep()}} for further information.} \item{inset}{integer(1). The table inset for the row or table being constructed. See \code{\link[formatters]{table_inset}}.} diff --git a/man/tabclasses.Rd b/man/tabclasses.Rd index 2c74806b8..69bd45993 100644 --- a/man/tabclasses.Rd +++ b/man/tabclasses.Rd @@ -117,7 +117,8 @@ tables that need a divider between them.} \item{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 \code{-} elsewhere (with a once per session warning).} +charset, and to \code{-} elsewhere (with a once per session warning). See +\code{\link[formatters:default_horizontal_sep]{formatters::set_default_hsep()}} for further information.} \item{trailing_section_div}{character(1). String which will be used as a section divider after the printing of the last row contained in this (sub)-table, diff --git a/man/table_shell.Rd b/man/table_shell.Rd index 824266d7c..31fa94f06 100644 --- a/man/table_shell.Rd +++ b/man/table_shell.Rd @@ -27,18 +27,24 @@ table_shell_str( \item{tt}{\code{TableTree} (or related class). A \code{TableTree} object representing a populated table.} -\item{widths}{widths of row.name and columns} +\item{widths}{numeric (or \code{NULL}). (proposed) widths for the columns +of \code{x}. The expected length of this numeric vector can be +retrieved with \code{ncol() + 1} as the column of row names must +also be considered.} -\item{col_gap}{gap between columns} +\item{col_gap}{numeric(1). Space (in characters) between columns} -\item{hsep}{character to create line separator} +\item{hsep}{character(1). Characters to repeat to create +header/body separator line. If \code{NULL}, the object value will be +used. If \code{" "}, an empty separator will be printed. Check \code{\link[formatters:default_hsep]{default_hsep()}} +for more information.} \item{tf_wrap}{logical(1). Should the texts for title, subtitle, and footnotes be wrapped?} -\item{max_width}{integer(1), character(1) or NULL. Width that title +\item{max_width}{integer(1), character(1) or \code{NULL}. Width that title and footer (including footnotes) materials should be -word-wrapped to. If NULL, it is set to the current print width +word-wrapped to. If \code{NULL}, it is set to the current print width of the session (\code{getOption("width")}). If set to \code{"auto"}, the width of the table (plus any table inset) is used. Ignored completely if \code{tf_wrap} is \code{FALSE}.} diff --git a/man/tostring.Rd b/man/tostring.Rd index 00fb3e691..05903fbc1 100644 --- a/man/tostring.Rd +++ b/man/tostring.Rd @@ -16,13 +16,19 @@ ) } \arguments{ -\item{x}{table object} +\item{x}{ANY. Object to be prepared for rendering.} -\item{widths}{widths of row.name and columns} +\item{widths}{numeric (or \code{NULL}). (proposed) widths for the columns +of \code{x}. The expected length of this numeric vector can be +retrieved with \code{ncol() + 1} as the column of row names must +also be considered.} -\item{col_gap}{gap between columns} +\item{col_gap}{numeric(1). Space (in characters) between columns} -\item{hsep}{character to create line separator} +\item{hsep}{character(1). Characters to repeat to create +header/body separator line. If \code{NULL}, the object value will be +used. If \code{" "}, an empty separator will be printed. Check \code{\link[formatters:default_hsep]{default_hsep()}} +for more information.} \item{indent_size}{numeric(1). Number of spaces to use per indent level. Defaults to 2} @@ -30,9 +36,9 @@ Defaults to 2} \item{tf_wrap}{logical(1). Should the texts for title, subtitle, and footnotes be wrapped?} -\item{max_width}{integer(1), character(1) or NULL. Width that title +\item{max_width}{integer(1), character(1) or \code{NULL}. Width that title and footer (including footnotes) materials should be -word-wrapped to. If NULL, it is set to the current print width +word-wrapped to. If \code{NULL}, it is set to the current print width of the session (\code{getOption("width")}). If set to \code{"auto"}, the width of the table (plus any table inset) is used. Ignored completely if \code{tf_wrap} is \code{FALSE}.} diff --git a/man/tt_to_flextable.Rd b/man/tt_to_flextable.Rd index 64ecd92a6..8befa8e87 100644 --- a/man/tt_to_flextable.Rd +++ b/man/tt_to_flextable.Rd @@ -81,9 +81,9 @@ regardless of page size.} \item{tf_wrap}{logical(1). Should the texts for title, subtitle, and footnotes be wrapped?} -\item{max_width}{integer(1), character(1) or NULL. Width that title +\item{max_width}{integer(1), character(1) or \code{NULL}. Width that title and footer (including footnotes) materials should be -word-wrapped to. If NULL, it is set to the current print width +word-wrapped to. If \code{NULL}, it is set to the current print width of the session (\code{getOption("width")}). If set to \code{"auto"}, the width of the table (plus any table inset) is used. Ignored completely if \code{tf_wrap} is \code{FALSE}.} diff --git a/tests/testthat/test-printing.R b/tests/testthat/test-printing.R index e944e1553..0ab5f8dd0 100644 --- a/tests/testthat/test-printing.R +++ b/tests/testthat/test-printing.R @@ -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) +})