Skip to content
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

New helper function for knit_print methods #789

Open
Puzzled-Face opened this issue Feb 6, 2024 · 0 comments
Open

New helper function for knit_print methods #789

Puzzled-Face opened this issue Feb 6, 2024 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers low priority

Comments

@Puzzled-Face
Copy link
Collaborator

The following code fragments are emerging as common features of knit_print methods. helper functions may be appropriate.

Labels for counts of 1 and >1

knit_print.foo <- function(x, ..., label = c("patient", "patients")) {
  assert_character(label, min.len = 1, max.len = 2, any.missing = FALSE)

  if (length(label) == 1) {
    label[2] <- paste0(label[1], "s")
  }
  ....
}

Provide default values for ...

knit_print.foo <- function(x, ...) {
  param <- list(...)
  if (!("col.names" %in% names(param))) {
    param[["col.names"]] <- c("Lower", "Upper", <some label>)
  }
  if (!("caption" %in% names(param))) {
    param[["caption"]] <- <some caption>
  }
  x <- tidy(x)
  param[["x"]] <- x
  rv <- kableExtra::add_header_above(
    do.call(knitr::kable, param),
    c(<some label> = 2, " " = 1)
  )
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers low priority
Projects
Status: To do
Development

No branches or pull requests

1 participant