Skip to content

Commit

Permalink
Merge pull request #778 from mccarthy-m-g/coef_rename-poly
Browse files Browse the repository at this point in the history
Add arguments to rename polynomials with `coef_rename()`
  • Loading branch information
vincentarelbundock authored Jun 16, 2024
2 parents 693e0f3 + 4ef5099 commit 32848c0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<doi:10.18637/jss.v103.i01>.
Version: 2.1.1
Version: 2.1.1.1
Authors@R: c(person("Vincent", "Arel-Bundock",
email = "[email protected]",
role = c("aut", "cre"),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions R/coef_rename.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' @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 backticks boolean remove backticks
#' @param titlecase boolean convert to title case
#' @param underscore boolean replace underscores by spaces
Expand All @@ -24,6 +25,7 @@
coef_rename <- function(x,
factor = TRUE,
factor_name = TRUE,
poly = TRUE,
backticks = TRUE,
titlecase = TRUE,
underscore = TRUE,
Expand All @@ -36,6 +38,10 @@ coef_rename <- function(x,
out <- gsub("factor\\((.*)\\)", "\\1 ", out)
}

if (isTRUE(poly)) {
out <- gsub("poly\\(([^,]*),.*\\)", "\\1^", out)
}

if (isTRUE(underscore)) {
out <- gsub("_", " ", out)
}
Expand Down
3 changes: 3 additions & 0 deletions man/coef_rename.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 32848c0

Please sign in to comment.