-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
301 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#' Modify source note | ||
#' | ||
#' @description | ||
#' Add and remove source notes from a table. | ||
#' Source notes are similar to footnotes, expect they are not linked to a cell in | ||
#' the table. | ||
#' | ||
#' @param x (`gtsummary`)\cr | ||
#' A gtsummary object. | ||
#' @param source_note (`string`)\cr | ||
#' A string to add as a source note. | ||
#' @param source_note_id (`integers`)\cr | ||
#' Integers specifying the ID of the source note to remove. | ||
#' Source notes are indexed sequentially at the time of creation. | ||
#' @inheritParams modify | ||
#' | ||
#' @details | ||
#' Source notes are not supported by `as_kable_extra()`. | ||
#' | ||
#' | ||
#' @return gtsummary object | ||
#' @name modify_source_note | ||
#' | ||
#' @examplesIf identical(Sys.getenv("NOT_CRAN"), "true") || identical(Sys.getenv("IN_PKGDOWN"), "true") | ||
#' | ||
NULL | ||
|
||
#' @export | ||
#' @rdname modify_source_note | ||
modify_source_note <- function(x, source_note, text_interpret = c("md", "html")) { | ||
set_cli_abort_call() | ||
updated_call_list <- c(x$call_list, list(modify_source_note = match.call())) | ||
|
||
# check inputs --------------------------------------------------------------- | ||
check_not_missing(x) | ||
check_not_missing(source_note) | ||
check_class(x, "gtsummary") | ||
check_string(source_note) | ||
text_interpret <- arg_match(text_interpret, error_call = get_cli_abort_call()) | ||
|
||
# add source note to table_styling ------------------------------------------- | ||
x$table_styling$source_note <- | ||
dplyr::bind_rows( | ||
x$table_styling$source_note, | ||
dplyr::tibble( | ||
id = nrow(x$table_styling$source_note) + 1L, | ||
source_note = source_note, | ||
text_interpret = paste0("gt::", text_interpret), | ||
remove = FALSE | ||
) | ||
) | ||
|
||
# return table --------------------------------------------------------------- | ||
x$call_list <- updated_call_list | ||
x | ||
} | ||
|
||
#' @export | ||
#' @rdname modify_source_note | ||
remove_source_note <- function(x, source_note_id) { | ||
set_cli_abort_call() | ||
updated_call_list <- c(x$call_list, list(remove_source_note = match.call())) | ||
|
||
# check inputs --------------------------------------------------------------- | ||
check_not_missing(x) | ||
check_not_missing(source_note_id) | ||
check_class(x, "gtsummary") | ||
check_integerish(source_note_id, allow_empty = TRUE) | ||
|
||
# mark source note for removal ----------------------------------------------- | ||
if (!is_empty(source_note_id)) { | ||
if (any(!source_note_id %in% x$table_styling$source_note$id)) { | ||
cli::cli_abort( | ||
c("Argument {.arg source_note_id} is out of bounds.", | ||
i = "Must be one or more of {.val {x$table_styling$source_note$id}} or {.code NULL}."), | ||
call = get_cli_abort_call() | ||
) | ||
} | ||
|
||
x$table_styling$source_note$remove[x$table_styling$source_note$id %in% source_note_id] <- TRUE | ||
} | ||
else { | ||
x$table_styling$source_note$remove <- TRUE | ||
} | ||
|
||
# return table --------------------------------------------------------------- | ||
x$call_list <- updated_call_list | ||
x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# modify_source_note() messaging | ||
|
||
Code | ||
modify_source_note(tbl_summary(trial, include = trt), source_note = letters) | ||
Condition | ||
Error in `modify_source_note()`: | ||
! The `source_note` argument must be a string, not a character vector. | ||
|
||
--- | ||
|
||
Code | ||
modify_source_note(tbl_summary(trial, include = trt), source_note = "ttt", | ||
text_interpret = letters) | ||
Condition | ||
Error in `modify_source_note()`: | ||
! `text_interpret` must be one of "md" or "html", not "a". | ||
|
||
# remove_source_note(source_note_id) messaging | ||
|
||
Code | ||
remove_source_note(modify_source_note(tbl_summary(trial, include = trt), | ||
"Created June 26, 2015"), source_note_id = 100) | ||
Condition | ||
Error in `remove_source_note()`: | ||
! Argument `source_note_id` is out of bounds. | ||
i Must be one or more of 1 or `NULL`. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.