From 74e656f5af7c990ad88d5c2ea91be508826ae8e5 Mon Sep 17 00:00:00 2001 From: Duncan Murdoch Date: Mon, 3 Jun 2024 14:53:00 -0400 Subject: [PATCH 1/2] Use rmarkdown as the VignetteBuilder. Handle empty factor level. --- DESCRIPTION | 4 ++-- NEWS.md | 7 +++++++ R/All.R | 2 +- R/RowFactor.R | 2 +- R/makeName.R | 6 ++++++ R/tabular.R | 4 ++-- 6 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 R/makeName.R diff --git a/DESCRIPTION b/DESCRIPTION index d36847e..37c01fd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: tables Title: Formula-Driven Table Generation -Version: 0.9.25 +Version: 0.9.26 Author: Duncan Murdoch Description: Computes and displays complex tables of summary statistics. Output may be in LaTeX, HTML, plain text, or an R @@ -11,7 +11,7 @@ Depends: R (>= 2.12.0) Imports: stats, utils, knitr, htmltools Suggests: magrittr, kableExtra (>= 0.9.0), Hmisc, bookdown, rmarkdown, pkgdown, formatters, tinytable (>= 0.0.5) -VignetteBuilder: knitr +VignetteBuilder: rmarkdown URL: https://dmurdoch.github.io/tables/ BugReports: https://github.com/dmurdoch/tables/issues SystemRequirements: pandoc (>= 1.12.3) for vignettes diff --git a/NEWS.md b/NEWS.md index d87d080..4bf8b8c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +# tables 0.9.26 + +- A factor level of `""` caused an error when displayed. It will +now be changed to `" "` for display (issue #19). +- The `VignetteBuilder` field in `DESCRIPTION` has been changed to +`rmarkdown` so that Pandoc will be found. + # tables 0.9.25 - `PlusMinus()` and `Paste()` didn't handle formatting properly diff --git a/R/All.R b/R/All.R index fee7826..3483858 100644 --- a/R/All.R +++ b/R/All.R @@ -39,7 +39,7 @@ All <- function(df, else next - f1 <- call("*", call("Heading", as.name(names[i])), + f1 <- call("*", call("Heading", makeName(names[i])), value) if (is.null(f)) f <- f1 diff --git a/R/RowFactor.R b/R/RowFactor.R index 198861a..b1f497b 100644 --- a/R/RowFactor.R +++ b/R/RowFactor.R @@ -60,7 +60,7 @@ RowFactor <- function(x, name = deparse(expr), levelnames=levels(x), test <- call("labelSubset", subset = call("==", call("as.integer", call("as.factor", expr)), i), label = deparse(expr)) - term <- call("*", call("Heading", as.name(catname)), + term <- call("*", call("Heading", makeName(catname)), test) if (i == 1) f <- term diff --git a/R/makeName.R b/R/makeName.R new file mode 100644 index 0000000..7df8ee6 --- /dev/null +++ b/R/makeName.R @@ -0,0 +1,6 @@ +makeName <- function(s) { + stopifnot(length(s) == 1) + if (!nchar(s)) + s <- " " + as.name(s) +} diff --git a/R/tabular.R b/R/tabular.R index 3691a23..e697515 100644 --- a/R/tabular.R +++ b/R/tabular.R @@ -553,10 +553,10 @@ expandFactors <- function(e, env) { rhs <- expandFactors(e[[3]], env) if (is.call(rhs) && deparse(rhs[[1]]) == "*" && is.call(rhs[[2]]) && deparse(rhs[[c(2,1)]]) == "Heading") { - rhs[[c(2,2)]] <- as.name(deparse(e[[2]])) + rhs[[c(2,2)]] <- makeName(deparse(e[[2]])) rhs } else - call("*", call("Heading", as.name(deparse(e[[2]]))), rhs) + call("*", call("Heading", makeName(deparse(e[[2]]))), rhs) } else if (op == ".Format" || op == "Heading" || op == "Justify" || op == "Percent" || op == "Arguments" || op == "DropEmpty") From 9e48935816a1aee280b0f3e2171f1156e4626d7f Mon Sep 17 00:00:00 2001 From: Duncan Murdoch Date: Mon, 3 Jun 2024 15:04:45 -0400 Subject: [PATCH 2/2] Fix check errors --- .github/workflows/R-CMD-check.yaml | 2 +- NEWS.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 24634c5..de04b82 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -35,7 +35,7 @@ jobs: - uses: r-lib/actions/setup-tinytex@v2 - run: tlmgr --version - - run: tlmgr install colortbl grfext ae + - run: tlmgr install colortbl grfext ae tabu - run: tlmgr list --only-installed - uses: r-lib/actions/setup-r@v2 with: diff --git a/NEWS.md b/NEWS.md index 4bf8b8c..c312bc1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,7 +3,7 @@ - A factor level of `""` caused an error when displayed. It will now be changed to `" "` for display (issue #19). - The `VignetteBuilder` field in `DESCRIPTION` has been changed to -`rmarkdown` so that Pandoc will be found. +`rmarkdown` so that Pandoc can be found even when it is not on the `PATH`. # tables 0.9.25