-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add arguments to rename polynomials with coef_rename()
#778
Add arguments to rename polynomials with coef_rename()
#778
Conversation
Oh thanks, this is a really great idea! Awesome. Two questions:
|
Welcome! Regarding your questions:
This approach just lets us clean up x <- list(
lm(mpg ~ I(cyl^1) + I(cyl^2) + drat + disp, data = mtcars),
lm(mpg ~ poly(cyl, 2, raw = TRUE) + drat + disp, data = mtcars)
)
modelsummary(x, coef_rename = \(.x) coef_rename(.x, poly_name = FALSE)) So the intention isn't to print the exponents in superscript---just as is. I don't believe this should break any output formats unless you attempt to apply some post-processing to the string that results in something breaking. But if that's the case you'd need special handling for
I think it makes sense to stick with a boolean argument for What we could do though is reduce it to a single boolean argument for the |
Got it. Yes, let's simplify to a single bool with the style you prefer. The ^ character should really be tested in a latex document though (or Quarto/Rmd PDF), because I think it's a special character. If that's the case and it breaks compilation, we either need some more complicated logic to escape conditionally on output format (would be a pain to code), or we need to come up with a different default style. |
Oh I see your point about I think that works because modelsummary escapes this character by default. So we're fine on that front. |
Awesome. I simplified the code to do the x <- list(
lm(mpg ~ I(cyl^1) + I(cyl^2) + drat + disp, data = mtcars),
lm(mpg ~ poly(cyl, 2, raw = TRUE) + drat + disp, data = mtcars)
)
modelsummary(x, coef_rename = coef_rename) Since |
Thanks a ton for this! Looks great. I merged. The latest release was only a few days ago, so it'll take a little bit before this gets to CRAN, but it should be available on Github and R-Universe in the next few minutes. |
Happy to contribute! I've been using modelsummary frequently for the example articles of a data package I'm working on and it's been super useful. Thanks for merging! |
This PR updates
coef_rename()
to handle polynomial coefficients created by thepoly()
function, similar to how the function currently handles factors. Here's some reprex code to check the new functionality out:Note that I didn't update
NEWS
or add any tests yet (I'm unfamiliar withtinytest
, so I'm unsure how to go about it).