From 0a208c79f4d3fb049989c065c322cd615c314d3d Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Sat, 1 Mar 2025 06:32:20 -0500 Subject: [PATCH 01/10] Prepare for release --- DESCRIPTION | 4 +++- NEWS.md | 3 +++ inst/WORDLIST | 4 ++++ tests/spelling.R | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 NEWS.md create mode 100644 inst/WORDLIST create mode 100644 tests/spelling.R diff --git a/DESCRIPTION b/DESCRIPTION index 31a380d..b64e01c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: tabtibble Title: Simplify Reporting Many Tables -Version: 0.0.0.9000 +Version: 0.0.1 Authors@R: person("Bill", "Denney", email="wdenney@humanpredictions.com", role=c("aut", "cre"), comment=c(ORCID="0000-0002-5759-428X")) Description: What the package does (one paragraph). @@ -16,6 +16,7 @@ Suggests: glue, pander, rmarkdown, + spelling, testthat (>= 3.0.0), tibble, tidyr @@ -23,3 +24,4 @@ Config/testthat/edition: 3 URL: https://github.com/humanpred/tabtibble, https://humanpred.github.io/tabtibble/ BugReports: https://github.com/humanpred/tabtibble/issues VignetteBuilder: knitr +Language: en-US diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..ed854a2 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,3 @@ +# tabtibble 0.0.1 + +* Initial CRAN submission. diff --git a/inst/WORDLIST b/inst/WORDLIST new file mode 100644 index 0000000..b526042 --- /dev/null +++ b/inst/WORDLIST @@ -0,0 +1,4 @@ +CMD +Codecov +tablist +tibble diff --git a/tests/spelling.R b/tests/spelling.R new file mode 100644 index 0000000..6713838 --- /dev/null +++ b/tests/spelling.R @@ -0,0 +1,3 @@ +if(requireNamespace('spelling', quietly = TRUE)) + spelling::spell_check_test(vignettes = TRUE, error = FALSE, + skip_on_cran = TRUE) From bb8b4aae0711a8463dee6a72bc697e41b0426fd2 Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Sat, 1 Mar 2025 06:33:50 -0500 Subject: [PATCH 02/10] As sent to CRAN --- .Rbuildignore | 1 + CRAN-SUBMISSION | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 CRAN-SUBMISSION diff --git a/.Rbuildignore b/.Rbuildignore index 86ee5d9..132b7f9 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -6,3 +6,4 @@ ^pkgdown$ ^\.github$ ^LICENSE\.md$ +^CRAN-SUBMISSION$ diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION new file mode 100644 index 0000000..03eee8e --- /dev/null +++ b/CRAN-SUBMISSION @@ -0,0 +1,3 @@ +Version: 0.0.1 +Date: 2025-03-01 11:32:58 UTC +SHA: 0a208c79f4d3fb049989c065c322cd615c314d3d From fda815e754d415522bb88326d111340724a1a7c2 Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Sat, 8 Mar 2025 11:59:05 -0500 Subject: [PATCH 03/10] Generalize the printing method --- NAMESPACE | 3 ++- R/knit_print.R | 11 ++++++++--- R/tablist_printers.R | 12 ++++++++++-- man/knit_print.tab_list.Rd | 5 +++-- man/print_tablist_pander.Rd | 21 --------------------- man/print_tabtibble.Rd | 29 +++++++++++++++++++++++++++++ tests/testthat/test-knit_print.R | 2 +- 7 files changed, 53 insertions(+), 30 deletions(-) delete mode 100644 man/print_tablist_pander.Rd create mode 100644 man/print_tabtibble.Rd diff --git a/NAMESPACE b/NAMESPACE index 2066cfa..66927e7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,9 +4,10 @@ S3method(format,tab_list) S3method(knit_print,tab_list) S3method(knit_print,tab_tibble) S3method(print,tab_list) +S3method(print_tabtibble,default) S3method(vctrs::vec_ptype_abbr,tab_list) export(knit_print) export(new_tab_list) export(new_tab_tibble) -export(print_tablist_pander) +export(print_tabtibble) importFrom(knitr,knit_print) diff --git a/R/knit_print.R b/R/knit_print.R index c95387e..179e962 100644 --- a/R/knit_print.R +++ b/R/knit_print.R @@ -19,20 +19,25 @@ knit_print.tab_tibble <- function(x, ...) { #' @param x The `tab_list` object to print #' @param ... passed to `print_fun` #' @param caption The caption for each table as a character vector -#' @param print_fun A function taking arguments of `x` (one data.frame to +#' @param print_fun Override the default printing using `print_tabtibble`. If +#' provided it is a function taking arguments of `x` (one data.frame to #' print), `caption` (the caption for that data.frame), and `...`. #' @param tab_prefix,tab_suffix Any text to add before/after each figure (`NULL` #' to omit) #' @returns `x` invisibly #' @family knitters #' @export -knit_print.tab_list <- function(x, ..., caption, print_fun = print_tablist_pander, tab_prefix = NULL, tab_suffix = "\n\n") { +knit_print.tab_list <- function(x, ..., caption, print_fun = NULL, tab_prefix = NULL, tab_suffix = "\n\n") { stopifnot(length(x) == length(caption)) for (idx in seq_along(x)) { if (!is.null(tab_prefix)) { cat(tab_prefix) } - print_fun(x = x[[idx]], caption = caption[[idx]], ...) + if (is.null(print_fun)) { + print_tabtibble(x = x[[idx]], caption = caption[[idx]], ...) + } else { + print_fun(x = x[[idx]], caption = caption[[idx]], ...) + } if (!is.null(tab_suffix)) { cat(tab_suffix) } diff --git a/R/tablist_printers.R b/R/tablist_printers.R index 3ff0973..af07c03 100644 --- a/R/tablist_printers.R +++ b/R/tablist_printers.R @@ -1,10 +1,18 @@ -#' Print a tablist using `pander::pander()` +#' Print a single table from a tablist +#' #' @param x A table to print #' @param caption The caption for the table +#' @param ... Passed to subsequent methods +#' @export +print_tabtibble <- function(x, caption, ...) { + UseMethod("print_tabtibble") +} + +#' @describeIn print_tabtibble Print a single table from a tablist using `pander::pander()` #' @param ... Passed to `pander::pander` #' @returns The result of `pander::pander` #' @export -print_tablist_pander <- function(x, caption, ...) { +print_tabtibble.default <- function(x, caption, ...) { auto_asis_start <- pander::panderOptions("knitr.auto.asis") on.exit(pander::panderOptions("knitr.auto.asis", auto_asis_start)) pander::panderOptions("knitr.auto.asis", FALSE) diff --git a/man/knit_print.tab_list.Rd b/man/knit_print.tab_list.Rd index 64a281e..ea28850 100644 --- a/man/knit_print.tab_list.Rd +++ b/man/knit_print.tab_list.Rd @@ -8,7 +8,7 @@ x, ..., caption, - print_fun = print_tablist_pander, + print_fun = NULL, tab_prefix = NULL, tab_suffix = "\\n\\n" ) @@ -20,7 +20,8 @@ \item{caption}{The caption for each table as a character vector} -\item{print_fun}{A function taking arguments of \code{x} (one data.frame to +\item{print_fun}{Override the default printing using \code{print_tabtibble}. If +provided it is a function taking arguments of \code{x} (one data.frame to print), \code{caption} (the caption for that data.frame), and \code{...}.} \item{tab_prefix, tab_suffix}{Any text to add before/after each figure (\code{NULL} diff --git a/man/print_tablist_pander.Rd b/man/print_tablist_pander.Rd deleted file mode 100644 index 3862d36..0000000 --- a/man/print_tablist_pander.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/tablist_printers.R -\name{print_tablist_pander} -\alias{print_tablist_pander} -\title{Print a tablist using \code{pander::pander()}} -\usage{ -print_tablist_pander(x, caption, ...) -} -\arguments{ -\item{x}{A table to print} - -\item{caption}{The caption for the table} - -\item{...}{Passed to \code{pander::pander}} -} -\value{ -The result of \code{pander::pander} -} -\description{ -Print a tablist using \code{pander::pander()} -} diff --git a/man/print_tabtibble.Rd b/man/print_tabtibble.Rd new file mode 100644 index 0000000..aee5624 --- /dev/null +++ b/man/print_tabtibble.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tablist_printers.R +\name{print_tabtibble} +\alias{print_tabtibble} +\alias{print_tabtibble.default} +\title{Print a single table from a tablist} +\usage{ +print_tabtibble(x, caption, ...) + +\method{print_tabtibble}{default}(x, caption, ...) +} +\arguments{ +\item{x}{A table to print} + +\item{caption}{The caption for the table} + +\item{...}{Passed to \code{pander::pander}} +} +\value{ +The result of \code{pander::pander} +} +\description{ +Print a single table from a tablist +} +\section{Methods (by class)}{ +\itemize{ +\item \code{print_tabtibble(default)}: Print a single table from a tablist using \code{pander::pander()} + +}} diff --git a/tests/testthat/test-knit_print.R b/tests/testthat/test-knit_print.R index 9f7f082..ba6540d 100644 --- a/tests/testthat/test-knit_print.R +++ b/tests/testthat/test-knit_print.R @@ -1,4 +1,4 @@ -test_that("knit_print.tab_tibble (and implicitly knit_print.tab_list and print_tablist_pander)", { +test_that("knit_print.tab_tibble (and implicitly knit_print.tab_list and print_tabtibble.tab_pander)", { d_tab <- mtcars |> tidyr::nest(table = !"cyl") |> From a42ca009600df10f98404bda646f6c2cf0b47abe Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Sat, 8 Mar 2025 12:04:32 -0500 Subject: [PATCH 04/10] Remove |> based on CRAN request --- tests/testthat/test-knit_print.R | 10 +++------- tests/testthat/test-objects.R | 10 +++------- vignettes/example-usage.Rmd | 7 ++++--- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/tests/testthat/test-knit_print.R b/tests/testthat/test-knit_print.R index ba6540d..04324f1 100644 --- a/tests/testthat/test-knit_print.R +++ b/tests/testthat/test-knit_print.R @@ -1,11 +1,7 @@ test_that("knit_print.tab_tibble (and implicitly knit_print.tab_list and print_tabtibble.tab_pander)", { - d_tab <- - mtcars |> - tidyr::nest(table = !"cyl") |> - dplyr::mutate( - caption = glue::glue("Cars with {cyl} cylinders") - ) |> - new_tab_tibble() + d_tab_prep <- tidyr::nest(mtcars, table = !"cyl") + d_tab_prep <- dplyr::mutate(d_tab_prep, caption = glue::glue("Cars with {cyl} cylinders")) + d_tab <- new_tab_tibble(d_tab_prep) expect_output( suppressWarnings(knit_print(d_tab)), regexp = "Cars with 8 cylinders" diff --git a/tests/testthat/test-objects.R b/tests/testthat/test-objects.R index 360cc94..11f1cca 100644 --- a/tests/testthat/test-objects.R +++ b/tests/testthat/test-objects.R @@ -20,13 +20,9 @@ test_that("new_tab_list", { }) test_that("vctrs methods", { - d_tab <- - mtcars |> - tidyr::nest(table = !"cyl") |> - dplyr::mutate( - caption = glue::glue("Cars with {cyl} cylinders") - ) |> - new_tab_tibble() + d_tab_prep <- tidyr::nest(mtcars, table = !"cyl") + d_tab_prep <- dplyr::mutate(d_tab_prep, caption = glue::glue("Cars with {cyl} cylinders")) + d_tab <- new_tab_tibble(d_tab_prep) expect_output( print(d_tab), regexp = "Cars with 8 cylinders" diff --git a/vignettes/example-usage.Rmd b/vignettes/example-usage.Rmd index 6469024..db915d8 100644 --- a/vignettes/example-usage.Rmd +++ b/vignettes/example-usage.Rmd @@ -16,6 +16,7 @@ knitr::opts_chunk$set( ```{r setup} library(tabtibble) +library(dplyr) ``` The `tabtibble` package is typically used to create a list of tables for @@ -26,11 +27,11 @@ grouped together. ```{r example-setup} d_tab <- - mtcars |> - tidyr::nest(table = !"cyl") |> + mtcars %>% + tidyr::nest(table = !"cyl") %>% dplyr::mutate( caption = glue::glue("Cars with {cyl} cylinders") - ) |> + ) %>% new_tab_tibble() ``` From cc165fb29258f8b60206e655aed5c59321ef3a8e Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Sat, 8 Mar 2025 12:12:48 -0500 Subject: [PATCH 05/10] improve testing --- tests/testthat/test-knit_print.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/testthat/test-knit_print.R b/tests/testthat/test-knit_print.R index 04324f1..b0bd603 100644 --- a/tests/testthat/test-knit_print.R +++ b/tests/testthat/test-knit_print.R @@ -10,4 +10,10 @@ test_that("knit_print.tab_tibble (and implicitly knit_print.tab_list and print_t suppressWarnings(knit_print(d_tab, tab_prefix = "foo")), regexp = "foo" ) + + # print_fun uses a custom function + expect_output( + suppressWarnings(knit_print(d_tab, print_fun = function(x, ...) print(head(x, 1)))), + regexp = "mpg disp hp drat wt qsec vs am gear carb" + ) }) From 57485aa7dbd1c966a5a5fb42e14bdfc51fae6562 Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Sun, 9 Mar 2025 08:39:39 -0400 Subject: [PATCH 06/10] Clarify function used for writing tables --- R/knit_print.R | 5 +++++ man/knit_print.tab_list.Rd | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/R/knit_print.R b/R/knit_print.R index 179e962..bdf8bbe 100644 --- a/R/knit_print.R +++ b/R/knit_print.R @@ -16,6 +16,11 @@ knit_print.tab_tibble <- function(x, ...) { #' Print a tab_list #' +#' @details +#' Individual tables are printed with the `print_tabtibble()` S3 generic +#' function. +#' +#' #' @param x The `tab_list` object to print #' @param ... passed to `print_fun` #' @param caption The caption for each table as a character vector diff --git a/man/knit_print.tab_list.Rd b/man/knit_print.tab_list.Rd index ea28850..7369131 100644 --- a/man/knit_print.tab_list.Rd +++ b/man/knit_print.tab_list.Rd @@ -33,6 +33,10 @@ to omit)} \description{ Print a tab_list } +\details{ +Individual tables are printed with the \code{print_tabtibble()} S3 generic +function. +} \seealso{ Other knitters: \code{\link{knit_print.tab_tibble}()} From 1aaadbdaaf14786b45d4ffac46df15e53b9de06a Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Sun, 9 Mar 2025 08:43:39 -0400 Subject: [PATCH 07/10] As submitted to CRAN --- CRAN-SUBMISSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index 03eee8e..9bdfed0 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ Version: 0.0.1 -Date: 2025-03-01 11:32:58 UTC -SHA: 0a208c79f4d3fb049989c065c322cd615c314d3d +Date: 2025-03-09 12:42:36 UTC +SHA: 57485aa7dbd1c966a5a5fb42e14bdfc51fae6562 From 1b1cf0c321cafe31bac2cd1528fed6647892c720 Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Sun, 9 Mar 2025 09:16:44 -0400 Subject: [PATCH 08/10] Remove R 4.1 dependence --- R/objects.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/objects.R b/R/objects.R index 374e259..0450035 100644 --- a/R/objects.R +++ b/R/objects.R @@ -34,7 +34,7 @@ vec_ptype_abbr.tab_list <- function(x, ...) { #' @export format.tab_list <- function(x, ...) { - sprintf("A %s object", vapply(X = x, FUN = \(x) class(x)[1], FUN.VALUE = "")) + sprintf("A %s object", vapply(X = x, FUN = function(x) class(x)[1], FUN.VALUE = "")) } #' @export From fed8917e5216252c01ee4ff97e4454d7b2f763a7 Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Sun, 9 Mar 2025 10:29:12 -0400 Subject: [PATCH 09/10] Update detailed description --- DESCRIPTION | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index b64e01c..c3c98c5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,7 +3,9 @@ Title: Simplify Reporting Many Tables Version: 0.0.1 Authors@R: person("Bill", "Denney", email="wdenney@humanpredictions.com", role=c("aut", "cre"), comment=c(ORCID="0000-0002-5759-428X")) -Description: What the package does (one paragraph). +Description: Simplify reporting many tables by creating tibbles of tables. With + 'tabtibble', a tibble of tables is created with captions and automatic + printing using 'knit_print()'. License: GPL (>= 3) Encoding: UTF-8 Roxygen: list(markdown = TRUE) From cde2aee3cfba82eceba7e6b01bcb1c8fd39e3410 Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Sun, 9 Mar 2025 10:30:15 -0400 Subject: [PATCH 10/10] As submitted to CRAN --- CRAN-SUBMISSION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index 9bdfed0..a7cf184 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ Version: 0.0.1 -Date: 2025-03-09 12:42:36 UTC -SHA: 57485aa7dbd1c966a5a5fb42e14bdfc51fae6562 +Date: 2025-03-09 14:29:52 UTC +SHA: fed8917e5216252c01ee4ff97e4454d7b2f763a7