From 54dce999342b30d91e99a6ba30e437e563fa9ca0 Mon Sep 17 00:00:00 2001 From: munoztd0 Date: Thu, 7 May 2026 11:38:47 +0200 Subject: [PATCH 1/2] export: mf_col_widths Co-authored-by: Copilot --- NAMESPACE | 2 ++ NEWS.md | 2 ++ R/matrix_form.R | 4 ++++ man/mpf_accessors.Rd | 6 ++++++ tests/testthat/test-mpf_accessors.R | 12 ++++++++++++ 5 files changed, 26 insertions(+) create mode 100644 tests/testthat/test-mpf_accessors.R diff --git a/NAMESPACE b/NAMESPACE index 228966891..fd04757e0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,6 +5,7 @@ export("main_footer<-") export("main_title<-") export("mf_aligns<-") export("mf_cinfo<-") +export("mf_col_widths<-") export("mf_colgap<-") export("mf_display<-") export("mf_fontspec<-") @@ -59,6 +60,7 @@ export(make_row_df) export(matrix_form) export(mf_aligns) export(mf_cinfo) +export(mf_col_widths) export(mf_colgap) export(mf_display) export(mf_fontspec) diff --git a/NEWS.md b/NEWS.md index 39b814b8d..6f1cb2b91 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ ## formatters 0.5.12.9002 +* Export `mf_col_widths` accessor (getter and setter). + ## formatters 0.5.12 * Added `"default"` format label which behaves like `"xx"` in `format_value` but indicates formatting behavior can be inherited from parent structures in upstream code. * `round_type = "sas"` no longer displays a negative sign when negative values are rounded to zero. diff --git a/R/matrix_form.R b/R/matrix_form.R index a884c32c6..8c9e4669f 100644 --- a/R/matrix_form.R +++ b/R/matrix_form.R @@ -625,10 +625,14 @@ mf_col_paths <- function(mf) { } } +#' @export +#' @rdname mpf_accessors mf_col_widths <- function(mf) { mf$col_widths } +#' @export +#' @rdname mpf_accessors `mf_col_widths<-` <- function(mf, value) { if (!is.null(value) && length(value) != NCOL(mf_strings(mf))) { stop( diff --git a/man/mpf_accessors.Rd b/man/mpf_accessors.Rd index f7c8f3aca..8670e12cd 100644 --- a/man/mpf_accessors.Rd +++ b/man/mpf_accessors.Rd @@ -16,6 +16,8 @@ \alias{mf_colgap} \alias{mf_fontspec} \alias{mf_fontspec<-} +\alias{mf_col_widths} +\alias{mf_col_widths<-} \alias{mf_strings<-} \alias{mf_spans<-} \alias{mf_aligns<-} @@ -65,6 +67,10 @@ mf_fontspec(mf) mf_fontspec(mf) <- value +mf_col_widths(mf) + +mf_col_widths(mf) <- value + mf_strings(mf) <- value mf_spans(mf) <- value diff --git a/tests/testthat/test-mpf_accessors.R b/tests/testthat/test-mpf_accessors.R new file mode 100644 index 000000000..b62549c6a --- /dev/null +++ b/tests/testthat/test-mpf_accessors.R @@ -0,0 +1,12 @@ +test_that("mf_col_widths getter and setter are available and work", { + mf <- basic_matrix_form(mtcars) + + # getter returns numeric vector + cw <- mf_col_widths(mf) + expect_true(is.numeric(cw)) + + # setter updates widths + new <- rep(10L, NCOL(mf_strings(mf))) + mf_col_widths(mf) <- new + expect_equal(mf_col_widths(mf), new) +}) From 482bd9812dd2102b64e6bd856c190c9e05c36994 Mon Sep 17 00:00:00 2001 From: munoztd0 Date: Wed, 13 May 2026 11:27:26 +0200 Subject: [PATCH 2/2] fix: spellcheck --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 6f1cb2b91..adfab0989 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ ## formatters 0.5.12.9002 -* Export `mf_col_widths` accessor (getter and setter). +* Export `mf_col_widths` accessor (`getter` and `setter`). ## formatters 0.5.12 * Added `"default"` format label which behaves like `"xx"` in `format_value` but indicates formatting behavior can be inherited from parent structures in upstream code.