Skip to content

Commit b4a85d3

Browse files
committed
Merge branch 'main' into fix_content_row_end
2 parents c4fd5fd + 21f1aae commit b4a85d3

23 files changed

+319
-101
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# R specific hooks: https://github.com/lorenzwalthert/precommit
33
repos:
44
- repo: https://github.com/lorenzwalthert/precommit
5-
rev: v0.3.2.9023
5+
rev: v0.3.2.9027
66
hooks:
77
# - id: style-files
88
# args: [--style_pkg=styler, --style_fun=tidyverse_style]

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: formatters
22
Title: ASCII Formatting for Values and Tables
3-
Version: 0.5.4.9002
4-
Date: 2023-10-19
3+
Version: 0.5.4.9005
4+
Date: 2023-11-27
55
Authors@R: c(
66
person("Gabriel", "Becker", , "[email protected]", role = "aut",
77
comment = "original creator of the package"),
@@ -51,6 +51,7 @@ Collate:
5151
'generics.R'
5252
'labels.R'
5353
'mpf_exporters.R'
54+
'package.R'
5455
'page_size.R'
5556
'pagination.R'
5657
'tostring.R'

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export(propose_column_widths)
8888
export(prov_footer)
8989
export(ref_df_row)
9090
export(round_fmt)
91+
export(set_default_hsep)
9192
export(spans_to_viscell)
9293
export(spread_integer)
9394
export(sprintf_format)

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
## formatters 0.5.4.9002
1+
## formatters 0.5.4.9005
22
* Applied `styler` and resolved package lint. Changed default indentation from 4 spaces to 2.
33
* Allow tables with content rows in the end be exported.
4+
* Fixed wrapping and section dividers error.
5+
* Allowed section divider between header and table body.
6+
* Added the possibility of setting a general default using `set_default_hsep()` that sets up the option `getOption("formatters_default_hsep")`.
47

58
## formatters 0.5.4
69
* Fixed a bug in `paginate_to_mpfs()` so that formatting in listings key columns is retained with pagination [`insightsengineering/rlistings#155`](https://github.com/insightsengineering/rlistings/issues/155).

R/format_value.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#' @importFrom htmltools tags tagList
2-
31
formats_1d <- c(
42
"xx", "xx.", "xx.x", "xx.xx", "xx.xxx", "xx.xxxx",
53
"xx%", "xx.%", "xx.x%", "xx.xx%", "xx.xxx%", "(N=xx)", ">999.9", ">999.99",

R/generics.R

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,3 +639,40 @@ setGeneric("num_rep_cols", function(obj) standardGeneric("num_rep_cols"))
639639
#' @export
640640
#' @rdname num_rep_cols
641641
setMethod("num_rep_cols", "ANY", function(obj) 0L)
642+
643+
# header_section_div -----------------------------------------------------------
644+
#' @keywords internal
645+
setGeneric("header_section_div", function(obj) standardGeneric("header_section_div"))
646+
#' @keywords internal
647+
setMethod(
648+
"header_section_div", "MatrixPrintForm",
649+
function(obj) obj$header_section_div
650+
)
651+
#' @keywords internal
652+
setGeneric("header_section_div<-", function(obj, value) standardGeneric("header_section_div<-"))
653+
#' @keywords internal
654+
setMethod(
655+
"header_section_div<-", "MatrixPrintForm",
656+
function(obj, value) {
657+
obj$header_section_div <- value
658+
obj
659+
}
660+
)
661+
# horizontal_sep ---------------------------------------------------------------
662+
#' @keywords internal
663+
setGeneric("horizontal_sep", function(obj) standardGeneric("horizontal_sep"))
664+
#' @keywords internal
665+
setMethod(
666+
"horizontal_sep", "MatrixPrintForm",
667+
function(obj) obj$horizontal_sep
668+
)
669+
#' @keywords internal
670+
setGeneric("horizontal_sep<-", function(obj, value) standardGeneric("horizontal_sep<-"))
671+
#' @keywords internal
672+
setMethod(
673+
"horizontal_sep<-", "MatrixPrintForm",
674+
function(obj, value) {
675+
obj$horizontal_sep <- value
676+
obj
677+
}
678+
)

R/matrix_form.R

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,12 @@ disp_from_spans <- function(spans) {
191191
#' @param page_titles character. Page-specific titles, as a character
192192
#' vector.
193193
#' @param main_footer character(1). Main footer as a string.
194-
#' @param prov_footer character. Provenance footer information as a
194+
#' @param prov_footer character. Provenance footer information as a
195195
#' character vector.
196+
#' @param header_section_div character(1). Divider to be used between header
197+
#' and body sections.
198+
#' @param horizontal_sep character(1). Horizontal separator to be used for printing
199+
#' divisors between header and table body and between different footers.
196200
#' @param expand_newlines logical(1). Should the matrix form generated
197201
#' expand rows whose values contain newlines into multiple
198202
#' 'physical' rows (as they will appear when rendered into
@@ -224,6 +228,8 @@ disp_from_spans <- function(spans) {
224228
#' \item{\code{page_titles}}{see argument}
225229
#' \item{\code{main_footer}}{see argument}
226230
#' \item{\code{prov_footer}}{see argument}
231+
#' \item{\code{header_section_div}}{see argument}
232+
#' \item{\code{horizontal_sep}}{see argument}
227233
#' \item{\code{col_gap}}{see argument}
228234
#' \item{\code{table_inset}}{see argument}
229235
#' }
@@ -252,6 +258,8 @@ MatrixPrintForm <- function(strings = NULL,
252258
page_titles = character(),
253259
main_footer = "",
254260
prov_footer = character(),
261+
header_section_div = NA_character_,
262+
horizontal_sep = default_hsep(),
255263
col_gap = 3,
256264
table_inset = 0L,
257265
colwidths = NULL,
@@ -274,6 +282,8 @@ MatrixPrintForm <- function(strings = NULL,
274282
page_titles = page_titles,
275283
main_footer = main_footer,
276284
prov_footer = prov_footer,
285+
header_section_div = header_section_div,
286+
horizontal_sep = horizontal_sep,
277287
col_gap = col_gap,
278288
table_inset = as.integer(table_inset),
279289
has_topleft = has_topleft,
@@ -399,7 +409,7 @@ infer_ref_info <- function(mform, colspace_only) {
399409
ret$col_path <- replicate(nrow(ret), list(NA_character_))
400410
non_na_col <- !is.na(ret$col)
401411
ret$col_path[non_na_col] <- col_pths[ret$col[non_na_col]]
402-
ret$ref_index <- seq_len(nrow(ret))
412+
ret$ref_index <- match(ret$symbol, unique(ret$symbol))
403413
##
404414
ret$nlines <- vapply(paste0("{", ret$symbol, "} - ", ret$msg), nlines, 1L)
405415
ret <- ret[, names(ref_df_row())]
@@ -891,20 +901,6 @@ reconstruct_basic_fnote_list <- function(mf) {
891901
paste0("{", refdf$symbol, "} - ", refdf$msg)
892902
}
893903

894-
895-
fix_fnote_df <- function(df) {
896-
ind_symb <- df$symbol == as.character(df$ref_index)
897-
df$ref_index <- seq_len(nrow(df))
898-
df$symbol[ind_symb] <- as.character(df$ref_index[ind_symb])
899-
df
900-
}
901-
902-
903-
904-
905-
906-
907-
908904
.mf_subset_core_mats <- function(mf, i, row = TRUE) {
909905
fillnum <- if (row) nrow(mf_strings(mf)) - mf_nlheader(mf) else ncol(mf)
910906
if (is.logical(i) || all(i < 0)) {
@@ -975,8 +971,10 @@ mpf_subset_rows <- function(mf, i) {
975971

976972
ncs <- ncol(mf)
977973
mf <- .mf_subset_core_mats(mf, i, row = TRUE)
978-
map <- data.frame(old_idx = c(seq_len(ncolrows), i + ncolrows),
979-
new_idx = c(seq_len(ncolrows), ncolrows + order(i)))
974+
map <- data.frame(
975+
old_idx = c(seq_len(ncolrows), i + ncolrows),
976+
new_idx = c(seq_len(ncolrows), ncolrows + order(i))
977+
)
980978

981979
row_map <- data.frame(old_idx = i, new_idx = order(i))
982980

@@ -985,7 +983,6 @@ mpf_subset_rows <- function(mf, i) {
985983
old_nas <- is.na(refdf$row)
986984
refdf$row <- map_to_new(refdf$row, row_map)
987985
refdf <- refdf[old_nas | !is.na(refdf$row), ]
988-
refdf <- fix_fnote_df(refdf)
989986
mf_fnote_df(mf) <- refdf
990987

991988
rinfo <- mf_rinfo(mf)

R/mpf_exporters.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export_as_txt <- function(x,
4747
cpp = NA_integer_,
4848
lpp = NA_integer_,
4949
...,
50-
hsep = default_hsep(),
50+
hsep = NULL,
5151
indent_size = 2,
5252
tf_wrap = paginate,
5353
max_width = NULL,
@@ -57,6 +57,8 @@ export_as_txt <- function(x,
5757
rep_cols = num_rep_cols(x),
5858
verbose = FALSE,
5959
page_break = "\\s\\n") {
60+
61+
6062
if (paginate) {
6163
pages <- paginate_to_mpfs(
6264
x,

R/package.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#' formatters Package
2+
#'
3+
#' Package to format tables and listings in a flexible way.
4+
#'
5+
"_PACKAGE"
6+
7+
#' @importFrom stats na.omit
8+
#' @importFrom utils head tail localeToCharset
9+
#' @importFrom htmltools tags tagList
10+
#' @import checkmate
11+
NULL

0 commit comments

Comments
 (0)