-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* gtsummary v2.0 preparation * Update R-CMD-check.yaml * Update DESCRIPTION * doc update * Update DESCRIPTION * Update DESCRIPTION * Update NEWS.md * Adding new functions to _pkgdown.yml. * updates --------- Co-authored-by: Teng Fei <[email protected]>
- Loading branch information
1 parent
543851c
commit 2ba26f1
Showing
14 changed files
with
417 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: tidycmprsk | ||
Title: Competing Risks Estimation | ||
Version: 1.0.0.9000 | ||
Version: 1.0.0.9001 | ||
Authors@R: c( | ||
person(c("Daniel", "D."), "Sjoberg", , "[email protected]", role = c("aut", "cre", "cph"), | ||
comment = c(ORCID = "0000-0003-0862-2018")), | ||
|
@@ -16,22 +16,25 @@ License: AGPL (>= 3) | |
URL: https://mskcc-epi-bio.github.io/tidycmprsk/, https://github.com/MSKCC-Epi-Bio/tidycmprsk | ||
BugReports: https://github.com/MSKCC-Epi-Bio/tidycmprsk/issues | ||
Depends: | ||
R (>= 3.4) | ||
R (>= 4.2) | ||
Imports: | ||
broom (>= 1.0.1), | ||
cli (>= 3.1.0), | ||
cmprsk (>= 2.2.10), | ||
dplyr (>= 1.0.7), | ||
ggplot2 (>= 3.3.5), | ||
gtsummary (>= 1.7.2), | ||
gtsummary (>= 2.0.0), | ||
hardhat (>= 1.3.0), | ||
purrr (>= 0.3.4), | ||
rlang (>= 1.0.0), | ||
stringr (>= 1.4.0), | ||
survival, | ||
tibble (>= 3.1.6), | ||
tidyr (>= 1.1.4) | ||
Suggests: | ||
Suggests: | ||
aod, | ||
broom.helpers (>= 1.15.0), | ||
cardx (>= 0.2.0), | ||
covr (>= 3.5.1), | ||
ggsurvfit, | ||
knitr (>= 1.36), | ||
|
@@ -42,4 +45,4 @@ Encoding: UTF-8 | |
Language: en-US | ||
LazyData: true | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.2.3 | ||
RoxygenNote: 7.3.2 |
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,41 @@ | ||
#' gtsummary methods | ||
#' | ||
#' @description | ||
#' These functions are S3 methods for working with [`tidycmprsk::crr()`] model | ||
#' results. | ||
#' | ||
#' - `tbl_regression.tidycrr()`: This function sets the tidycmprsk tidier for `crr()` models. | ||
#' - `global_pvalue_fun.tidycrr()`: This function ensures that `gtsummary::add_global_p(anova_fun)` uses | ||
#' the Wald test by default (instead of `car::Anova()`, which does not support this model type). | ||
#' The Wald test is executed with `cardx::ard_aod_wald_test()`, which wraps `aod::wald.test()`. | ||
#' | ||
#' @param x (`tidycrr`)\cr | ||
#' `tidycmprsk::crr()` regression object | ||
#' @param tidy_fun (`function`)\cr | ||
#' Tidier function for the model. Default is `tidycmprsk::tidy()`. | ||
#' @param type not used | ||
#' @inheritParams gtsummary::tbl_regression | ||
#' | ||
#' @name gtsummary_s3_methods | ||
#' @return gtsummary table or data frame of results | ||
#' | ||
#' @examples | ||
#' crr(Surv(ttdeath, death_cr) ~ age + grade, trial) |> | ||
#' gtsummary::tbl_regression() |> | ||
#' gtsummary::add_global_p() |> | ||
#' gtsummary::as_gt() | ||
NULL | ||
|
||
#' @rdname gtsummary_s3_methods | ||
#' @export | ||
tbl_regression.tidycrr <- function(x, tidy_fun = tidycmprsk::tidy, ...) { | ||
asNamespace("gtsummary")[["tbl_regression.default"]](x = x, tidy_fun = tidy_fun, ...) | ||
} | ||
|
||
#' @rdname gtsummary_s3_methods | ||
#' @export | ||
global_pvalue_fun.tidycrr <- function(x, type, ...) { | ||
check_pkg_installed("cardx", reference_pkg = "tidycmprisk") | ||
|
||
cardx::ard_aod_wald_test(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
# Standalone file: do not edit by hand | ||
# Source: <https://github.com/ddsjoberg/standalone/blob/main/R/standalone-check_pkg_installed.R> | ||
# ---------------------------------------------------------------------- | ||
# | ||
# --- | ||
# repo: ddsjoberg/standalone | ||
# file: standalone-check_pkg_installed.R | ||
# last-updated: 2024-04-19 | ||
# license: https://unlicense.org | ||
# dependencies: standalone-cli_call_env.R | ||
# imports: [rlang, dplyr, tidyr] | ||
# --- | ||
# | ||
# This file provides functions to check package installation. | ||
# | ||
# ## Changelog | ||
# nocov start | ||
# styler: off | ||
|
||
#' Check Package Installation | ||
#' | ||
#' @description | ||
#' - `check_pkg_installed()`: checks whether a package is installed and | ||
#' returns an error if not available, or interactively asks user to install | ||
#' missing dependency. If a package search is provided, | ||
#' the function will check whether a minimum version of a package is required and installed. | ||
#' | ||
#' - `is_pkg_installed()`: checks whether a package is installed and | ||
#' returns `TRUE` or `FALSE` depending on availability. If a package search is provided, | ||
#' the function will check whether a minimum version of a package is required and installed. | ||
#' | ||
#' - `get_pkg_dependencies()` returns a tibble with all | ||
#' dependencies of a specific package. | ||
#' | ||
#' - `get_min_version_required()` will return, if any, the minimum version | ||
#' of `pkg` required by `reference_pkg`. | ||
#' | ||
#' @param pkg (`character`)\cr | ||
#' vector of package names to check. | ||
#' @param call (`environment`)\cr | ||
#' frame for error messaging. Default is [get_cli_abort_call()]. | ||
#' @param reference_pkg (`string`)\cr | ||
#' name of the package the function will search for a minimum required version from. | ||
#' @param lib.loc (`path`)\cr | ||
#' location of `R` library trees to search through, see [utils::packageDescription()]. | ||
#' | ||
#' @return `is_pkg_installed()` and `check_pkg_installed()` returns a logical or error, | ||
#' `get_min_version_required()` returns a data frame with the minimum version required, | ||
#' `get_pkg_dependencies()` returns a tibble. | ||
#' | ||
#' @examples | ||
#' check_pkg_installed("dplyr") | ||
#' | ||
#' is_pkg_installed("dplyr") | ||
#' | ||
#' get_pkg_dependencies() | ||
#' | ||
#' get_min_version_required("dplyr") | ||
#' | ||
#' @name check_pkg_installed | ||
#' @noRd | ||
NULL | ||
|
||
#' @inheritParams check_pkg_installed | ||
#' @keywords internal | ||
#' @noRd | ||
check_pkg_installed <- function(pkg, | ||
reference_pkg = "cards", | ||
call = get_cli_abort_call()) { | ||
# get min version data ------------------------------------------------------- | ||
df_pkg_min_version <- | ||
get_min_version_required(pkg = pkg, reference_pkg = reference_pkg, call = call) | ||
|
||
# prompt user to install package --------------------------------------------- | ||
rlang::check_installed( | ||
pkg = df_pkg_min_version$pkg, | ||
version = df_pkg_min_version$version, | ||
compare = df_pkg_min_version$compare | ||
) |> | ||
# this can be removed after this issue is resolved https://github.com/r-lib/rlang/issues/1694 | ||
suppressWarnings() | ||
} | ||
|
||
#' @inheritParams check_pkg_installed | ||
#' @keywords internal | ||
#' @noRd | ||
is_pkg_installed <- function(pkg, | ||
reference_pkg = "cards", | ||
call = get_cli_abort_call()) { | ||
# get min version data ------------------------------------------------------- | ||
df_pkg_min_version <- | ||
get_min_version_required(pkg = pkg, reference_pkg = reference_pkg, call = call) | ||
|
||
# check installation TRUE/FALSE ---------------------------------------------- | ||
rlang::is_installed( | ||
pkg = df_pkg_min_version$pkg, | ||
version = df_pkg_min_version$version, | ||
compare = df_pkg_min_version$compare | ||
) |> | ||
# this can be removed after this issue is resolved https://github.com/r-lib/rlang/issues/1694 | ||
suppressWarnings() | ||
} | ||
|
||
#' @inheritParams check_pkg_installed | ||
#' @keywords internal | ||
#' @noRd | ||
get_pkg_dependencies <- function(reference_pkg = "cards", lib.loc = NULL, call = get_cli_abort_call()) { | ||
if (rlang::is_empty(reference_pkg)) { | ||
return(.empty_pkg_deps_df()) | ||
} | ||
|
||
description <- utils::packageDescription(reference_pkg, lib.loc = lib.loc) |> suppressWarnings() | ||
if (identical(description, NA)) { | ||
return(.empty_pkg_deps_df()) | ||
} | ||
description |> | ||
unclass() |> | ||
dplyr::as_tibble() |> | ||
dplyr::select( | ||
dplyr::any_of(c( | ||
"Package", "Version", "Imports", "Depends", | ||
"Suggests", "Enhances", "LinkingTo" | ||
)) | ||
) |> | ||
dplyr::rename( | ||
reference_pkg = "Package", | ||
reference_pkg_version = "Version" | ||
) |> | ||
tidyr::pivot_longer( | ||
-dplyr::all_of(c("reference_pkg", "reference_pkg_version")), | ||
values_to = "pkg", | ||
names_to = "dependency_type", | ||
) |> | ||
tidyr::separate_rows("pkg", sep = ",") |> | ||
dplyr::mutate( | ||
pkg = trimws( | ||
x = gsub(x = .data$pkg, pattern = "\\s+", replacement = " "), | ||
which = "both", whitespace = "[ \t\r\n]" | ||
) | ||
) |> | ||
dplyr::filter(!is.na(.data$pkg)) |> | ||
tidyr::separate( | ||
.data$pkg, | ||
into = c("pkg", "version"), | ||
sep = " ", extra = "merge", fill = "right" | ||
) |> | ||
dplyr::mutate( | ||
compare = .data$version |> stringr::str_extract(pattern = "[>=<]+"), | ||
version = .data$version |> stringr::str_remove_all(pattern = "[\\(\\) >=<]") | ||
) | ||
} | ||
|
||
.empty_pkg_deps_df <- function() { | ||
dplyr::tibble( | ||
reference_pkg = character(0L), reference_pkg_version = character(0L), | ||
dependency_type = character(0L), pkg = character(0L), | ||
version = character(0L), compare = character(0L) | ||
) | ||
} | ||
|
||
#' @inheritParams check_pkg_installed | ||
#' @keywords internal | ||
#' @noRd | ||
get_min_version_required <- function(pkg, reference_pkg = "cards", | ||
lib.loc = NULL, call = get_cli_abort_call()) { | ||
# if no package reference, return a df with just the pkg names | ||
if (rlang::is_empty(reference_pkg)) { | ||
return( | ||
.empty_pkg_deps_df() |> | ||
dplyr::full_join( | ||
dplyr::tibble(pkg = pkg), | ||
by = "pkg" | ||
) | ||
) | ||
} | ||
|
||
# get the package_ref deps and subset on requested pkgs, also supplement df with pkgs | ||
# that may not be proper deps of the reference package (these pkgs don't have min versions) | ||
res <- | ||
get_pkg_dependencies(reference_pkg, lib.loc = lib.loc) |> | ||
dplyr::filter(.data$pkg %in% .env$pkg) |> | ||
dplyr::full_join( | ||
dplyr::tibble(pkg = pkg), | ||
by = "pkg" | ||
) | ||
|
||
res | ||
} | ||
|
||
# nocov end | ||
# styler: on |
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,53 @@ | ||
# Standalone file: do not edit by hand | ||
# Source: <https://github.com/ddsjoberg/standalone/blob/main/R/standalone-cli_call_env.R> | ||
# ---------------------------------------------------------------------- | ||
# | ||
# --- | ||
# repo: ddsjoberg/standalone | ||
# file: standalone-cli_call_env.R | ||
# last-updated: 2024-04-10 | ||
# license: https://unlicense.org | ||
# imports: [rlang, cli] | ||
# --- | ||
# | ||
# This file provides functions to set and access the call environment to use in cli::cli_abort() in check functions. | ||
# | ||
# ## Changelog | ||
# nocov start | ||
# styler: off | ||
|
||
#' Set Call Environment for [cli::cli_abort()] | ||
#' | ||
#' Set a call environment to be used as the `call` parameter in [cli::cli_abort()] for package checks. This function | ||
#' is used to ensure that the correct user-facing function is reported for errors generated by internal checks that | ||
#' use [cli::cli_abort()]. | ||
#' | ||
#' @param env (`enviroment`)\cr | ||
#' call environment used as the `call` parameter in [cli::cli_abort()] for package checks | ||
#' | ||
#' @seealso [get_cli_abort_call()] | ||
#' | ||
#' @keywords internal | ||
#' @noRd | ||
set_cli_abort_call <- function(env = rlang::caller_env()) { | ||
if (getOption("cli_abort_call") |> is.null()) { | ||
options(cli_abort_call = env) | ||
set_call <- as.call(list(function() options(cli_abort_call = NULL))) | ||
do.call(on.exit, list(expr = set_call, add = TRUE, after = FALSE), envir = env) | ||
} | ||
invisible() | ||
} | ||
|
||
#' Get Call Environment for [cli::cli_abort()] | ||
#' | ||
#' @inheritParams set_cli_abort_call | ||
#' @seealso [set_cli_abort_call()] | ||
#' | ||
#' @keywords internal | ||
#' @noRd | ||
get_cli_abort_call <- function() { | ||
getOption("cli_abort_call", default = parent.frame()) | ||
} | ||
|
||
# nocov end | ||
# styler: on |
Oops, something went wrong.