From 700e01cc8a496375b54f697d59a15b4c17bd6f74 Mon Sep 17 00:00:00 2001 From: Michael McCarthy <51542091+mccarthy-m-g@users.noreply.github.com> Date: Thu, 13 Jun 2024 15:59:31 -0700 Subject: [PATCH 1/4] add arguments to rename polynomials --- R/coef_rename.R | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/R/coef_rename.R b/R/coef_rename.R index b24ff1d3d..81a73c554 100644 --- a/R/coef_rename.R +++ b/R/coef_rename.R @@ -7,6 +7,9 @@ #' @param factor boolean remove the "factor()" label #' @param factor_name boolean remove the "factor()" label and the name of the #' variable +#' @param poly boolean remove the "poly()" label and function arguments +#' @param poly_name boolean remove the "poly()" label, function arguments, and +#' the name of the variable #' @param backticks boolean remove backticks #' @param titlecase boolean convert to title case #' @param underscore boolean replace underscores by spaces @@ -24,6 +27,8 @@ coef_rename <- function(x, factor = TRUE, factor_name = TRUE, + poly = TRUE, + poly_name = TRUE, backticks = TRUE, titlecase = TRUE, underscore = TRUE, @@ -36,6 +41,12 @@ coef_rename <- function(x, out <- gsub("factor\\((.*)\\)", "\\1 ", out) } + if (isTRUE(poly_name)) { + out <- gsub("poly\\(.*\\)", "^", out) + } else if (isTRUE(poly)) { + out <- gsub("poly\\(([^,]*),.*\\)", "\\1^", out) + } + if (isTRUE(underscore)) { out <- gsub("_", " ", out) } From 32c35f9b7ba1b8d62a72b84a2e5767f9e6e3e743 Mon Sep 17 00:00:00 2001 From: Michael McCarthy <51542091+mccarthy-m-g@users.noreply.github.com> Date: Thu, 13 Jun 2024 16:19:02 -0700 Subject: [PATCH 2/4] add documentation for renaming polynomials --- man/coef_rename.Rd | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/man/coef_rename.Rd b/man/coef_rename.Rd index a3d5c0f61..649bac916 100644 --- a/man/coef_rename.Rd +++ b/man/coef_rename.Rd @@ -8,6 +8,8 @@ coef_rename( x, factor = TRUE, factor_name = TRUE, + poly = TRUE, + poly_name = TRUE, backticks = TRUE, titlecase = TRUE, underscore = TRUE, @@ -22,6 +24,11 @@ coef_rename( \item{factor_name}{boolean remove the "factor()" label and the name of the variable} +\item{poly}{boolean remove the "poly()" label and function arguments} + +\item{poly_name}{boolean remove the "poly()" label, function arguments, and +the name of the variable} + \item{backticks}{boolean remove backticks} \item{titlecase}{boolean convert to title case} From 67121ed57abaa52ca2f6ddcd49bfd5a9239911ea Mon Sep 17 00:00:00 2001 From: Michael McCarthy <51542091+mccarthy-m-g@users.noreply.github.com> Date: Fri, 14 Jun 2024 17:10:03 -0700 Subject: [PATCH 3/4] simplify implementation for renaming `poly()` coefficients --- R/coef_rename.R | 7 +------ man/coef_rename.Rd | 4 ---- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/R/coef_rename.R b/R/coef_rename.R index 81a73c554..cf8379a85 100644 --- a/R/coef_rename.R +++ b/R/coef_rename.R @@ -8,8 +8,6 @@ #' @param factor_name boolean remove the "factor()" label and the name of the #' variable #' @param poly boolean remove the "poly()" label and function arguments -#' @param poly_name boolean remove the "poly()" label, function arguments, and -#' the name of the variable #' @param backticks boolean remove backticks #' @param titlecase boolean convert to title case #' @param underscore boolean replace underscores by spaces @@ -28,7 +26,6 @@ coef_rename <- function(x, factor = TRUE, factor_name = TRUE, poly = TRUE, - poly_name = TRUE, backticks = TRUE, titlecase = TRUE, underscore = TRUE, @@ -41,9 +38,7 @@ coef_rename <- function(x, out <- gsub("factor\\((.*)\\)", "\\1 ", out) } - if (isTRUE(poly_name)) { - out <- gsub("poly\\(.*\\)", "^", out) - } else if (isTRUE(poly)) { + if (isTRUE(poly)) { out <- gsub("poly\\(([^,]*),.*\\)", "\\1^", out) } diff --git a/man/coef_rename.Rd b/man/coef_rename.Rd index 649bac916..618ebbcba 100644 --- a/man/coef_rename.Rd +++ b/man/coef_rename.Rd @@ -9,7 +9,6 @@ coef_rename( factor = TRUE, factor_name = TRUE, poly = TRUE, - poly_name = TRUE, backticks = TRUE, titlecase = TRUE, underscore = TRUE, @@ -26,9 +25,6 @@ variable} \item{poly}{boolean remove the "poly()" label and function arguments} -\item{poly_name}{boolean remove the "poly()" label, function arguments, and -the name of the variable} - \item{backticks}{boolean remove backticks} \item{titlecase}{boolean convert to title case} From 4ef5099315bbda5d6cf6c5552bda325fe9d9dcf8 Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Sun, 16 Jun 2024 16:38:59 -0400 Subject: [PATCH 4/4] bump --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index cf93a23de..68f00e49c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,7 +9,7 @@ Description: Create beautiful and customizable tables to summarize several RTF, JPG, or PNG. Tables can easily be embedded in 'Rmarkdown' or 'knitr' dynamic documents. Details can be found in Arel-Bundock (2022) . -Version: 2.1.1 +Version: 2.1.1.1 Authors@R: c(person("Vincent", "Arel-Bundock", email = "vincent.arel-bundock@umontreal.ca", role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index 6934cce6d..17a83c3ce 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # News +## Development + +* `coef_rename()` gets a `poly=TRUE` argument to rename `poly(x, 2)`-style coefficients. Thanks to @mccarthy-m-g for code contribution #778. + ## 2.1.1 * Documentation improvements