diff --git a/NAMESPACE b/NAMESPACE index 22896689..fd04757e 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 39b814b8..adfab098 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 a884c32c..8c9e4669 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 f7c8f3ac..8670e12c 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 00000000..b62549c6 --- /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) +})