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

selectors such as all_categorical() are now compatible with gtsummary version ≥ 2.0.0 #271

Merged
merged 17 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ Depends:
R (>= 4.2)
Imports:
broom (>= 0.8),
cards,
cli,
dplyr,
dplyr (>= 1.1.0),
labelled,
lifecycle,
purrr,
Expand Down Expand Up @@ -49,7 +50,7 @@ Suggests:
glmmTMB,
glue,
gt,
gtsummary (>= 1.6.3),
gtsummary (>= 2.0.0),
knitr,
lavaan,
lfe,
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export(model_list_variables)
export(num_range)
export(one_of)
export(plot_marginal_predictions)
export(scope_tidy)
export(seq_range)
export(starts_with)
export(tidy_add_coefficients_type)
Expand Down Expand Up @@ -185,6 +186,7 @@ export(tidy_zeroinfl)
export(variables_to_contrast)
export(variables_to_predict)
export(vars)
export(where)
importFrom(cli,cli_alert_danger)
importFrom(cli,cli_alert_info)
importFrom(cli,cli_code)
Expand All @@ -201,6 +203,7 @@ importFrom(dplyr,num_range)
importFrom(dplyr,one_of)
importFrom(dplyr,starts_with)
importFrom(dplyr,vars)
importFrom(dplyr,where)
importFrom(lifecycle,deprecate_soft)
importFrom(purrr,"%||%")
importFrom(rlang,.data)
Expand Down
19 changes: 19 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
# broom.helpers (development version)

**Documentation**

- Documentation has been improved, showing now clearly the type expected
for each argument (#272)

**Deprecated functions and changes in selectors functions**

- selectors such as `all_categorical()` are now compatible with `gtsummary`
version ≥ 2.0.0 (#270)
- new function `scope_tidy()` to scope a tidy tibble allowing
to tidy select (#270)
- `.select_to_varnames()`, `.formula_list_to_named_list()`,
`.generic_selector()` and `.is_selector_scoped()` are now deprecated and
will be removed in a future release: you may consider
`cards::process_selectors()` and `cards::process_formula_selectors()` as
alternatives (#270)

**Fixes**

- `model_get_model_frame.coxph()` has been fixed to return a correct model
frame a subject identifier is passed to `survival::coxph()` (#268)


# broom.helpers 1.16.0

**New features**
Expand Down Expand Up @@ -39,6 +57,7 @@
(#260 @jackmwolf)
- `tidy_marginal_predictions()` has been updated to avoid the use of the
deprecated function `marginaleffects::datagridcf()` (#256)


# broom.helpers 1.15.0

Expand Down
18 changes: 12 additions & 6 deletions R/assert_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@
#' will return, if any, the minimum version of `pkg` required by `pkg_search`,
#' `NULL` if no minimum version required.
#'
#' @param pkg Package required
#' @param fn Calling function from the user perspective. Used to write
#' @param pkg (`string`)\cr
#' Name of the required package.
#' @param fn (`string`)\cr
#' Name of the calling function from the user perspective. Used to write
#' informative error messages.
#' @param pkg_search the package the function will search for a minimum
#' @param pkg_search (`string`)\cr
#' Name of the package the function will search for a minimum
#' required version from.
#' @param boolean logical indicating whether to return a `TRUE`/`FALSE`, rather
#' @param boolean (`logical`)\cr
#' Whether to return a `TRUE`/`FALSE`, rather
#' than error when package/package version not available. Default is `FALSE`,
#' which will return an error if `pkg` is not installed.
#' @param remove_duplicates if several versions of a package are installed,
#' @param remove_duplicates (`logical`)\cr
#' If several versions of a package are installed,
#' should only the first one be returned?
#' @param lib.loc location of `R` library trees to search through, see
#' @param lib.loc (`string`)\cr
#' Location of `R` library trees to search through, see
#' `utils::installed.packages()`.
#' @details
#' `get_all_packages_dependencies()` could be used to get the list of
Expand Down
8 changes: 5 additions & 3 deletions R/broom.helpers-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ NULL

# because `where` is not exported by tidyselect
# cf. https://github.com/r-lib/tidyselect/issues/201
utils::globalVariables(c(".", "where"))
utils::globalVariables(c("."))

# update named vectors, y values overriding x values if common name
.update_vector <- function(x, y) {
Expand Down Expand Up @@ -77,8 +77,10 @@ utils::globalVariables(c(".", "where"))

#' Sequence generation between min and max
#'
#' @param x a numeric vector
#' @param length.out desired length of the sequence
#' @param x (`numeric`)\cr
#' A numeric vector.
#' @param length.out (`integer`)\cr
#' Desired length of the sequence (a positive integer).
#' @details
#' `seq_range(x, length.out)` is a shortcut for
#' `seq(min(x, na.rm = TRUE), max(x, na.rm = TRUE), length.out = length.out)`
Expand Down
59 changes: 34 additions & 25 deletions R/custom_tidiers.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
#'
#' Use [parameters::model_parameters()] to tidy a model and apply
#' `parameters::standardize_names(style = "broom")` to the output
#' @param x a model
#' @param conf.int logical indicating whether or not to include a confidence
#' interval in the tidied output
#' @param conf.level the confidence level to use for the confidence interval
#' @param ... additional parameters passed to [parameters::model_parameters()]
#' @param x (a model object, e.g. `glm`)\cr
#' A model to be tidied.
#' @param conf.int (`logical`)\cr
#' Whether or not to include a confidence interval in the tidied output.
#' @param conf.level (`numeric`)\cr
#' The confidence level to use for the confidence interval (between `0` ans `1`).
#' @param ... Additional parameters passed to [parameters::model_parameters()].
#' @note
#' For [betareg::betareg()], the component column in the results is standardized
#' with [broom::tidy()], using `"mean"` and `"precision"` values.
Expand Down Expand Up @@ -71,12 +73,14 @@ tidy_parameters <- function(x, conf.int = TRUE, conf.level = .95, ...) {
#'
#' Try to tidy a model with `broom::tidy()`. If it fails, will try to tidy the
#' model using `parameters::model_parameters()` through `tidy_parameters()`.
#' @param x a model
#' @param conf.int logical indicating whether or not to include a confidence
#' interval in the tidied output
#' @param conf.level the confidence level to use for the confidence interval
#' @param ... additional parameters passed to `broom::tidy()` or
#' `parameters::model_parameters()`
#' @param x (a model object, e.g. `glm`)\cr
#' A model to be tidied.
#' @param conf.int (`logical`)\cr
#' Whether or not to include a confidence interval in the tidied output.
#' @param conf.level (`numeric`)\cr
#' The confidence level to use for the confidence interval (between `0` ans `1`).
#' @param ... Additional parameters passed to `broom::tidy()` or
#' `parameters::model_parameters()`.
#' @export
#' @family custom_tieders
tidy_with_broom_or_parameters <- function(x, conf.int = TRUE, conf.level = .95, ...) {
Expand Down Expand Up @@ -239,8 +243,9 @@ tidy_with_broom_or_parameters <- function(x, conf.int = TRUE, conf.level = .95,

#' Tidy with `broom::tidy()` and checks that all arguments are used
#'
#' @param x a model to tidy
#' @param ... additional parameters passed to `broom::tidy()`
#' @param x (a model object, e.g. `glm`)\cr
#' A model to be tidied.
#' @param ... Additional parameters passed to `broom::tidy()`.
#' @family custom_tieders
#' @export
tidy_broom <- function(x, ...) {
Expand All @@ -254,11 +259,13 @@ tidy_broom <- function(x, ...) {
#' A tidier for models generated with `multgee::nomLORgee()` or `multgee::ordLORgee()`.
#' Term names will be updated to be consistent with generic models. The original
#' term names are preserved in an `"original_term"` column.
#' @param x a `multgee::nomLORgee()` or a `multgee::ordLORgee()` model
#' @param conf.int logical indicating whether or not to include a confidence
#' interval in the tidied output
#' @param conf.level the confidence level to use for the confidence interval
#' @param ... additional parameters passed to `parameters::model_parameters()`
#' @param x (`LORgee`)\cr
#' A `multgee::nomLORgee()` or a `multgee::ordLORgee()` model.
#' @param conf.int (`logical`)\cr
#' Whether or not to include a confidence interval in the tidied output.
#' @param conf.level (`numeric`)\cr
#' The confidence level to use for the confidence interval (between `0` ans `1`).
#' @param ... Additional parameters passed to `parameters::model_parameters()`.
#' @details
#' To be noted, for `multgee::nomLORgee()`, the baseline `y` category is the
#' latest modality of `y`.
Expand Down Expand Up @@ -334,13 +341,15 @@ tidy_multgee <- function(x, conf.int = TRUE, conf.level = .95, ...) {
#' A tidier for models generated with `pscl::zeroinfl()` or `pscl::hurdle()`.
#' Term names will be updated to be consistent with generic models. The original
#' term names are preserved in an `"original_term"` column.
#' @param x a `pscl::zeroinfl()` or a `pscl::hurdle()` model
#' @param conf.int logical indicating whether or not to include a confidence
#' interval in the tidied output
#' @param conf.level the confidence level to use for the confidence interval
#' @param component `NULL` or one of `"all"`, `"conditional"`, `"zi"`, or
#' `"zero_inflated"`
#' @param ... additional parameters passed to `parameters::model_parameters()`
#' @param x (`zeroinfl` or `hurdle`)\cr
#' A `pscl::zeroinfl()` or a `pscl::hurdle()` model.
#' @param conf.int (`logical`)\cr
#' Whether or not to include a confidence interval in the tidied output.
#' @param conf.level (`numeric`)\cr
#' The confidence level to use for the confidence interval (between `0` ans `1`).
#' @param component (`string`)\cr
#' `NULL` or one of `"all"`, `"conditional"`, `"zi"`, or `"zero_inflated"`.
#' @param ... Additional parameters passed to `parameters::model_parameters()`.
#' @export
#' @family custom_tieders
#' @examplesIf interactive()
Expand Down
17 changes: 8 additions & 9 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#' meaning in a regular expression
#'
#' This functions has been adapted from `Hmisc::escapeRegex()`
#' @param string a character vector
#' @param string (`string`)\cr
#' A character vector.
#' @export
#' @family other_helpers
.escape_regex <- function(string) {
Expand All @@ -12,16 +13,14 @@
)
}



#' Remove backticks around variable names
#'
#' @param x a character vector to be cleaned
#' @param variable_names list of variable names,
#' could be obtained with
#' [model_list_variables(only_variable = TRUE)][model_list_variables()]
#' to properly take into account interaction only terms/variables
#'
#' @param x (`string`)\cr
#' A character vector to be cleaned.
#' @param variable_names (`string`)\cr
#' Optional vector of variable names, could be obtained with
#' [model_list_variables(only_variable = TRUE)][model_list_variables()],
#' to properly take into account interaction only terms/variables.
#' @export
#' @family other_helpers
.clean_backticks <- function(x, variable_names = x) {
Expand Down
Loading