diff --git a/DESCRIPTION b/DESCRIPTION index f2c175d6..f23abaf8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: crane Title: Supplements the 'gtsummary' Package for Pharmaceutical Reporting -Version: 0.3.1.9044 +Version: 0.3.2 Authors@R: c( person("Daniel D.", "Sjoberg", , "danield.sjoberg@gmail.com", role = "aut", comment = c(ORCID = "0000-0003-0862-2018", note = "Original creator of the package")), @@ -28,12 +28,12 @@ URL: https://github.com/insightsengineering/crane, https://insightsengineering.github.io/crane/ BugReports: https://github.com/insightsengineering/crane/issues Depends: - gtsummary (>= 2.5.0), + gtsummary (>= 2.5.1), R (>= 4.2) Imports: broom (>= 1.0.8), - cards (>= 0.7.0), - cardx (>= 0.3.0), + cards (>= 0.8.0), + cardx (>= 0.3.3), cli (>= 3.6.4), cowplot (>= 1.2.0), dplyr (>= 1.2.0), @@ -62,10 +62,6 @@ Suggests: tidyselect, withr (>= 3.0.1), yaml -Remotes: - ddsjoberg/gtsummary@main, - insightsengineering/cards@main, - insightsengineering/cardx@main Config/Needs/check: hms Config/Needs/website: rmarkdown, yaml Config/testthat/edition: 3 diff --git a/NEWS.md b/NEWS.md index 3e1d775a..bb797c91 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# crane 0.3.1.9044 +# crane 0.3.2 ## New Functions and Functionality diff --git a/R/add_forest.R b/R/add_forest.R index 725b2d3b..f5242412 100644 --- a/R/add_forest.R +++ b/R/add_forest.R @@ -52,19 +52,23 @@ #' add_forest(table_engine = "gt") #' #' # Realistic example --------------------------------------------------------- -#' trial |> -#' tbl_roche_subgroups( -#' rsp = "response", -#' by = "trt", -#' subgroups = c("grade"), -#' ~ glm(response ~ trt, data = .x) |> -#' gtsummary::tbl_regression( -#' show_single_row = trt, -#' exponentiate = TRUE # , tidy_fun = broom.helpers::tidy_parameters -#' ) -#' ) |> -#' add_forest(pvalue = starts_with("p.value"), table_engine = "flextable") |> -#' flextable::set_header_labels(ggplot = "---------") +#' \donttest{ +#' if (requireNamespace("broom.helpers", quietly = TRUE)) { +#' trial |> +#' tbl_roche_subgroups( +#' rsp = "response", +#' by = "trt", +#' subgroups = c("grade"), +#' ~ glm(response ~ trt, data = .x) |> +#' gtsummary::tbl_regression( +#' show_single_row = trt, +#' exponentiate = TRUE # , tidy_fun = broom.helpers::tidy_parameters +#' ) +#' ) |> +#' add_forest(pvalue = starts_with("p.value"), table_engine = "flextable") |> +#' flextable::set_header_labels(ggplot = "---------") +#' } +#' } #' @export add_forest <- function(x, estimate = starts_with("estimate"), diff --git a/R/adjust_stat_columns_wrap.R b/R/adjust_stat_columns_wrap.R index db6b7c25..81712fe0 100644 --- a/R/adjust_stat_columns_wrap.R +++ b/R/adjust_stat_columns_wrap.R @@ -16,8 +16,14 @@ #' Defaults to `"protect"`. #' #' @return A modified `gtsummary` object. -#' #' @export +#' @examples +#' tbl <- gtsummary::tbl_summary( +#' trial, +#' by = trt, +#' include = c(age, grade) +#' ) +#' adjust_stat_columns_wrap(tbl, "protect") adjust_stat_columns_wrap <- function(tbl, mode = c("protect", "unprotect")) { # Robustly match the argument (defaults to "protect" if not provided) mode <- rlang::arg_match(mode) diff --git a/R/annotate_gg_pkc.R b/R/annotate_gg_pkc.R index 58fd4104..4d319b8a 100644 --- a/R/annotate_gg_pkc.R +++ b/R/annotate_gg_pkc.R @@ -23,7 +23,7 @@ #' The font size for the table text. Defaults to `3.5`. #' @param rel_height_plot (`numeric`)\cr #' Relative height of the plot vs the table. Defaults to `0.75`. -#' +#' @returns A ggplot2 object: a plot with a table at the bottom. #' @seealso [gg_pkc_lineplot()] for related functionalities. #' @examples #' # Prepare PK Data using the built-in Theoph dataset diff --git a/R/deprecated.R b/R/deprecated.R index 59780335..3e73db42 100644 --- a/R/deprecated.R +++ b/R/deprecated.R @@ -5,6 +5,9 @@ #' supported. #' #' @name deprecated +#' @returns Warnings +#' @examples +#' NULL #' @keywords internal NULL @@ -25,7 +28,7 @@ tbl_demographics <- function(..., nonmissing = "always") { #' @export g_lineplot <- function(...) { lifecycle::deprecate_soft( - "0.3.1.9017", + "0.3.2", "crane::g_lineplot()", "crane::gg_lineplot" ) @@ -35,7 +38,7 @@ g_lineplot <- function(...) { #' @export g_lineplot_table <- function(...) { lifecycle::deprecate_soft( - "0.3.1.9017", + "0.3.2", "crane::g_lineplot_table()", "crane::annotate_gg()" ) @@ -45,7 +48,7 @@ g_lineplot_table <- function(...) { #' @export preprocess_lineplot_data <- function(...) { lifecycle::deprecate_soft( - "0.3.1.9017", + "0.3.2", "crane::preprocess_lineplot_data()", "crane::annotate_gg()" ) diff --git a/R/gg_km_utils.R b/R/gg_km_utils.R index 07674418..087ab4ce 100644 --- a/R/gg_km_utils.R +++ b/R/gg_km_utils.R @@ -10,6 +10,8 @@ #' @return A numeric vector of x-axis tick positions. #' #' @keywords internal +#' @examples +#' NULL h_xticks <- function(data, xticks = NULL, max_time = NULL) { if (is.null(xticks)) { if (is.null(max_time)) { @@ -46,6 +48,8 @@ h_xticks <- function(data, xticks = NULL, max_time = NULL) { #' @return A data frame with columns "N", "Median", and the confidence interval label. #' #' @keywords internal +#' @examples +#' NULL h_tbl_median_surv <- function(fit_km, strata_levels = "All") { y <- if (is.null(fit_km$strata)) { as.data.frame(t(summary(fit_km)$table), row.names = strata_levels) diff --git a/R/tbl_coxph.R b/R/tbl_coxph.R index 72a22dc1..222e3c6c 100644 --- a/R/tbl_coxph.R +++ b/R/tbl_coxph.R @@ -143,6 +143,14 @@ tbl_coxph <- function(pairwise_df) { #' @return A `gtsummary` object containing the stacked summary statistics. #' #' @keywords internal +#' @examples +#' tbl <- tibble::tibble( +#' comparison_label = "A-B", +#' hr_formatted = "5.21", +#' ci_formatted = "0.25-0.35", +#' pval_formatted = 0.005 +#' ) +#' crane:::.get_single_comp_table(tbl, pval_label = "p-val") .get_single_comp_table <- function(data_subset, pval_label = NULL) { # Check which pre-formatted columns made it into the subset has_pval <- "pval_formatted" %in% names(data_subset) @@ -214,6 +222,8 @@ tbl_coxph <- function(pairwise_df) { #' #' @returns A character vector of formatted p-values. #' @keywords internal +#' @examples +#' crane:::.format_pvalue(0.000156) .format_pvalue <- function(x) { if (is.character(x)) { return(x) diff --git a/R/tbl_listing.R b/R/tbl_listing.R index dc9ba3ee..2bbad49b 100644 --- a/R/tbl_listing.R +++ b/R/tbl_listing.R @@ -34,7 +34,7 @@ #' parameters used in [gtsummary::tbl_split_by_rows()]. See example 4. #' * Split by columns - you can split the data frame by columns by using `split_by_columns` parameter. Use the same #' parameters from [gtsummary::tbl_split_by_rows()]. See example 5. -#' +#' @returns A table listing of class "tbl_listing". #' @examplesIf crane:::is_pkg_installed("labelled") #' # Load the trial dataset #' trial_data <- trial |> diff --git a/R/tbl_null_report.R b/R/tbl_null_report.R index a86c0ba3..f499d4bb 100644 --- a/R/tbl_null_report.R +++ b/R/tbl_null_report.R @@ -4,7 +4,7 @@ #' #' @param label (`string`)\cr label to display in the header of the null report. It defaults to #' "No observations met the reporting criteria for this output." -#' +#' @returns A gtsummary object of class tbl_null_report. #' @examples #' tbl_null_report(label = "No data available for the selected criteria.") #' diff --git a/R/tbl_rmpt.R b/R/tbl_rmpt.R index 708f2944..5e3b08c7 100644 --- a/R/tbl_rmpt.R +++ b/R/tbl_rmpt.R @@ -84,6 +84,7 @@ #' #' # Example 2 -------------------------------- #' # Add overall column at the end +#' \donttest{ #' tbl_rmpt( #' data = df_adex, #' variable = AVAL_CAT, @@ -103,6 +104,7 @@ #' denominator = df_adsl, #' label = "Treatment Exposure Duration" #' ) +#' } #' NULL #' @rdname tbl_rmpt diff --git a/R/tbl_roche_subgroups.R b/R/tbl_roche_subgroups.R index ca8a9d68..d8506582 100644 --- a/R/tbl_roche_subgroups.R +++ b/R/tbl_roche_subgroups.R @@ -17,7 +17,7 @@ #' #' @returns a 'gtsummary' table #' -#' @examples +#' @examplesIf identical(Sys.getenv("NOT_CRAN"), "true") #' set.seed(1) #' #' # prepare sample data @@ -49,6 +49,7 @@ #' # coxph regression ---------------------------------------------------------- #' # please use browser() inside .tbl_fun to check if the coxph model throws an error #' # and use tryCatch to modify the input/output accordingly +#' \donttest{ #' df_adtte |> #' tbl_roche_subgroups( #' rsp = status, @@ -66,7 +67,7 @@ #' ) #' ) |> #' modify_header(starts_with("estimate") ~ "**Hazard Ratio**") -#' +#' } #' @export tbl_roche_subgroups <- function(data, rsp, by, subgroups, .tbl_fun, time_to_event = NULL) { set_cli_abort_call() diff --git a/README.md b/README.md index 7159e0bf..20d7909b 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ tbl <- trial |> tbl_roche_summary(by = trt, include = c(age, grade), nonmissing = "always") ``` - + The package also exports functions for Roche adverse event reporting, functions for shift tables, and others. diff --git a/man/add_forest.Rd b/man/add_forest.Rd index c7c4dc23..d8c1e1cd 100644 --- a/man/add_forest.Rd +++ b/man/add_forest.Rd @@ -77,17 +77,21 @@ trial |> add_forest(table_engine = "gt") # Realistic example --------------------------------------------------------- -trial |> - tbl_roche_subgroups( - rsp = "response", - by = "trt", - subgroups = c("grade"), - ~ glm(response ~ trt, data = .x) |> - gtsummary::tbl_regression( - show_single_row = trt, - exponentiate = TRUE # , tidy_fun = broom.helpers::tidy_parameters - ) - ) |> - add_forest(pvalue = starts_with("p.value"), table_engine = "flextable") |> - flextable::set_header_labels(ggplot = "---------") +\donttest{ +if (requireNamespace("broom.helpers", quietly = TRUE)) { + trial |> + tbl_roche_subgroups( + rsp = "response", + by = "trt", + subgroups = c("grade"), + ~ glm(response ~ trt, data = .x) |> + gtsummary::tbl_regression( + show_single_row = trt, + exponentiate = TRUE # , tidy_fun = broom.helpers::tidy_parameters + ) + ) |> + add_forest(pvalue = starts_with("p.value"), table_engine = "flextable") |> + flextable::set_header_labels(ggplot = "---------") +} +} } diff --git a/man/adjust_stat_columns_wrap.Rd b/man/adjust_stat_columns_wrap.Rd index 0e485e8b..ceb3101c 100644 --- a/man/adjust_stat_columns_wrap.Rd +++ b/man/adjust_stat_columns_wrap.Rd @@ -26,3 +26,11 @@ on a single line when protected. Column headers and labels remain unaffected. For the rare cases when protecting creates ugly squashed label column protection can be reversed using the same function. } +\examples{ +tbl <- gtsummary::tbl_summary( + trial, + by = trt, + include = c(age, grade) +) +adjust_stat_columns_wrap(tbl, "protect") +} diff --git a/man/annotate_pkc_df.Rd b/man/annotate_pkc_df.Rd index 17e5a828..5cbfd46d 100644 --- a/man/annotate_pkc_df.Rd +++ b/man/annotate_pkc_df.Rd @@ -42,6 +42,9 @@ The font size for the table text. Defaults to \code{3.5}.} \item{rel_height_plot}{(\code{numeric})\cr Relative height of the plot vs the table. Defaults to \code{0.75}.} } +\value{ +A ggplot2 object: a plot with a table at the bottom. +} \description{ These functions provide capabilities to annotate Pharmacokinetics plot (\code{\link[=gg_pkc_lineplot]{gg_pkc_lineplot()}}) with additional summary statistics table. diff --git a/man/deprecated.Rd b/man/deprecated.Rd index e6c60500..5a1d0f66 100644 --- a/man/deprecated.Rd +++ b/man/deprecated.Rd @@ -16,9 +16,15 @@ g_lineplot_table(...) preprocess_lineplot_data(...) } +\value{ +Warnings +} \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}}\cr Some functions have been deprecated and are no longer being actively supported. } +\examples{ +NULL +} \keyword{internal} diff --git a/man/dot-format_pvalue.Rd b/man/dot-format_pvalue.Rd index 1a2bda3a..9d32fd85 100644 --- a/man/dot-format_pvalue.Rd +++ b/man/dot-format_pvalue.Rd @@ -18,4 +18,7 @@ to four decimal places. Character input is returned as-is, allowing users to pre-format the p-value column in \code{pairwise_df} before calling \code{\link[=tbl_coxph]{tbl_coxph()}}. } +\examples{ +crane:::.format_pvalue(0.000156) +} \keyword{internal} diff --git a/man/dot-get_single_comp_table.Rd b/man/dot-get_single_comp_table.Rd index e7a80f43..86c62c41 100644 --- a/man/dot-get_single_comp_table.Rd +++ b/man/dot-get_single_comp_table.Rd @@ -22,4 +22,13 @@ Internal helper function to build a formatted \code{gtsummary} table for a singl comparison arm. It conditionally extracts available statistics from the subsetted data and stacks them into rows for the final display. } +\examples{ +tbl <- tibble::tibble( + comparison_label = "A-B", + hr_formatted = "5.21", + ci_formatted = "0.25-0.35", + pval_formatted = 0.005 +) +crane:::.get_single_comp_table(tbl, pval_label = "p-val") +} \keyword{internal} diff --git a/man/figures/README-tbl_print_simple-1.png b/man/figures/README-tbl_print_simple-1.png index d3d5301d..565c51f6 100644 Binary files a/man/figures/README-tbl_print_simple-1.png and b/man/figures/README-tbl_print_simple-1.png differ diff --git a/man/h_tbl_median_surv.Rd b/man/h_tbl_median_surv.Rd index 17812e95..cf227ca2 100644 --- a/man/h_tbl_median_surv.Rd +++ b/man/h_tbl_median_surv.Rd @@ -20,4 +20,7 @@ A data frame with columns "N", "Median", and the confidence interval label. Extracts and formats the median survival time and its confidence interval from a fitted Kaplan-Meier object. } +\examples{ +NULL +} \keyword{internal} diff --git a/man/h_xticks.Rd b/man/h_xticks.Rd index e61f4a50..a0807856 100644 --- a/man/h_xticks.Rd +++ b/man/h_xticks.Rd @@ -20,4 +20,7 @@ A numeric vector of x-axis tick positions. \description{ Determines the positions for x-axis ticks based on the data and user input. } +\examples{ +NULL +} \keyword{internal} diff --git a/man/tbl_listing.Rd b/man/tbl_listing.Rd index 90e2207d..8ab2b6d3 100644 --- a/man/tbl_listing.Rd +++ b/man/tbl_listing.Rd @@ -37,6 +37,9 @@ columns to highlight for duplicate values. If \code{NULL}, nothing is done.} \item{value}{(\code{string})\cr string to use for blank values. Defaults to \code{NA}. It should not be changed.} } +\value{ +A table listing of class "tbl_listing". +} \description{ This function creates a listing from a data frame. Common uses rely on few pre-processing steps, such as ensuring unique values in key columns or split diff --git a/man/tbl_null_report.Rd b/man/tbl_null_report.Rd index 9efe8f94..d820609a 100644 --- a/man/tbl_null_report.Rd +++ b/man/tbl_null_report.Rd @@ -12,6 +12,9 @@ tbl_null_report( \item{label}{(\code{string})\cr label to display in the header of the null report. It defaults to "No observations met the reporting criteria for this output."} } +\value{ +A gtsummary object of class tbl_null_report. +} \description{ This function creates a null report for tables or listings without any statistics. } diff --git a/man/tbl_rmpt.Rd b/man/tbl_rmpt.Rd index 08411dda..a5ad0995 100644 --- a/man/tbl_rmpt.Rd +++ b/man/tbl_rmpt.Rd @@ -120,6 +120,7 @@ tbl_rmpt( # Example 2 -------------------------------- # Add overall column at the end +\donttest{ tbl_rmpt( data = df_adex, variable = AVAL_CAT, @@ -139,5 +140,6 @@ tbl_rmpt( denominator = df_adsl, label = "Treatment Exposure Duration" ) +} } diff --git a/man/tbl_roche_subgroups.Rd b/man/tbl_roche_subgroups.Rd index 7ef0744f..7a81c361 100644 --- a/man/tbl_roche_subgroups.Rd +++ b/man/tbl_roche_subgroups.Rd @@ -36,6 +36,7 @@ a 'gtsummary' table Function adapted from \code{gtforester::tbl_subgroups()}. } \examples{ +\dontshow{if (identical(Sys.getenv("NOT_CRAN"), "true")) withAutoprint(\{ # examplesIf} set.seed(1) # prepare sample data @@ -62,11 +63,12 @@ df_adtte |> ) ) |> modify_header(starts_with("estimate") ~ "**Odds Ratio**") - +\dontshow{\}) # examplesIf} \dontshow{if (rlang::is_installed("survival")) withAutoprint(\{ # examplesIf} # coxph regression ---------------------------------------------------------- # please use browser() inside .tbl_fun to check if the coxph model throws an error # and use tryCatch to modify the input/output accordingly +\donttest{ df_adtte |> tbl_roche_subgroups( rsp = status, @@ -84,5 +86,6 @@ df_adtte |> ) ) |> modify_header(starts_with("estimate") ~ "**Hazard Ratio**") +} \dontshow{\}) # examplesIf} }