Skip to content

Commit c82b125

Browse files
fix: strip backticks from variable names in ard_car_vif()
When variable names contain spaces (e.g. 'Marker Level'), car::vif() returns them backtick-quoted (e.g. '`Marker Level`'). This caused a name mismatch with gtsummary::tbl_regression(), which stores variable names without backticks, resulting in empty VIF columns when joined via add_vif(). Use broom.helpers::.clean_backticks() to strip backticks from the variable column before pivoting to ARD structure. Fixes #335
1 parent 7c07c87 commit c82b125

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

R/ard_car_vif.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
#' @rdname ard_car_vif
1515
#' @export
1616
#'
17-
#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = "car"))
17+
#' @examplesIf do.call(asNamespace("cardx")$is_pkg_installed, list(pkg = c("car", "broom.helpers")))
1818
#' lm(AGE ~ ARM + SEX, data = cards::ADSL) |>
1919
#' ard_car_vif()
2020
ard_car_vif <- function(x, ...) {
2121
set_cli_abort_call()
2222

2323
# check installed packages ---------------------------------------------------
24-
check_pkg_installed("car")
24+
check_pkg_installed(c("car", "broom.helpers"))
2525

2626
# check inputs ---------------------------------------------------------------
2727
check_not_missing(x)
@@ -67,6 +67,7 @@ ard_car_vif <- function(x, ...) {
6767
# Clean-up the result to fit the ard structure through pivot
6868
vif$result <-
6969
vif$result |>
70+
dplyr::mutate(variable = broom.helpers::.clean_backticks(.data$variable)) |>
7071
tidyr::pivot_longer(
7172
cols = -c("variable"),
7273
names_to = "stat_name",

man/ard_car_vif.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)