From 279339b1d50da2c1c6c8d66bd6fe3a41765407d7 Mon Sep 17 00:00:00 2001 From: Brad Nolan <59341305+bnolan7@users.noreply.github.com> Date: Thu, 13 Oct 2022 11:50:11 -0400 Subject: [PATCH] Update ggforest.R Proposed fix for ggforest. Error was being presented when attempting to run ggforest with coxph model: Error in match.names(clabs, names(xi)) : names do not match previous names Isolated where column names for allTerms were using variable names, which would prevent rbind from working. By relabeling column names before rbind, ggforest functions as expected. R version 4.2.1 (2022-06-23 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19044) Matrix products: default locale: [1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8 LC_MONETARY=English_United States.utf8 [4] LC_NUMERIC=C LC_TIME=English_United States.utf8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ggstatsplot_0.9.4 survminer_0.4.9 ggpubr_0.4.0 survival_3.4-0 modelsummary_1.0.2 summarytools_1.0.1 [7] SAScii_1.0.1 labelled_2.10.0 forcats_0.5.2 stringr_1.4.1 dplyr_1.0.10 purrr_0.3.5 [13] readr_2.1.3 tidyr_1.2.1 tibble_3.1.8 ggplot2_3.3.6 tidyverse_1.3.2 loaded via a namespace (and not attached): [1] googledrive_2.0.0 colorspace_2.0-3 ggsignif_0.6.3 pryr_0.1.5 ellipsis_0.3.2 [6] markdown_1.1 parameters_0.19.0 base64enc_0.1-3 fs_1.5.2 gridtext_0.1.5 [11] ggtext_0.1.2 rstudioapi_0.14 farver_2.1.1 bit64_4.0.5 fansi_1.0.3 [16] lubridate_1.8.0 xml2_1.3.3 codetools_0.2-18 splines_4.2.1 cachem_1.0.6 [21] knitr_1.40 zeallot_0.1.0 Formula_1.2-4 jsonlite_1.8.2 broom_1.0.1 [26] km.ci_0.5-6 dbplyr_2.2.1 compiler_4.2.1 httr_1.4.4 backports_1.4.1 [31] assertthat_0.2.1 Matrix_1.5-1 fastmap_1.1.0 gargle_1.2.1 cli_3.4.1 [36] htmltools_0.5.3 tools_4.2.1 gtable_0.3.1 glue_1.6.2 reshape2_1.4.4 [41] tables_0.9.6 Rcpp_1.0.9 carData_3.0-5 jquerylib_0.1.4 cellranger_1.1.0 [46] vctrs_0.4.2 svglite_2.1.0 insight_0.18.5 xfun_0.33 rvest_1.0.3 [51] lifecycle_1.0.3 estimatr_1.0.0 rstatix_0.7.0 googlesheets4_1.0.1 MASS_7.3-57 [56] zoo_1.8-11 scales_1.2.1 vroom_1.6.0 hms_1.1.2 parallel_4.2.1 [61] rematch2_2.1.2 gridExtra_2.3 KMsurv_0.1-5 pander_0.6.5 sass_0.4.2 [66] stringi_1.7.8 paletteer_1.4.1 bayestestR_0.13.0 checkmate_2.1.0 systemfonts_1.0.4 [71] rlang_1.0.6 pkgconfig_2.0.3 matrixStats_0.62.0 evaluate_0.17 lattice_0.20-45 [76] labeling_0.4.2 patchwork_1.1.2 rapportools_1.1 cowplot_1.1.1 bit_4.0.4 [81] tidyselect_1.2.0 plyr_1.8.7 magrittr_2.0.3 R6_2.5.1 magick_2.7.3 [86] generics_0.1.3 DBI_1.1.3 pillar_1.8.1 haven_2.5.1 withr_2.5.0 [91] datawizard_0.6.2 abind_1.4-5 performance_0.10.0 modelr_0.1.9 crayon_1.5.2 [96] car_3.1-0 survMisc_0.5.6 utf8_1.2.2 correlation_0.8.3 tzdb_0.3.0 [101] rmarkdown_2.17 grid_4.2.1 readxl_1.4.1 data.table_1.14.2 webshot_0.5.4 [106] reprex_2.0.2 digest_0.6.29 xtable_1.8-4 statsExpressions_1.3.4 munsell_0.5.0 [111] viridisLite_0.4.1 kableExtra_1.3.4 bslib_0.4.0 tcltk_4.2.1 --- R/ggforest.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/ggforest.R b/R/ggforest.R index 3480206..793d171 100644 --- a/R/ggforest.R +++ b/R/ggforest.R @@ -72,8 +72,10 @@ ggforest <- function(model, data = NULL, pos = seq_along(vars)) } }) + for (i in 1:length(allTerms)) { + colnames(allTerms[[i]]) <- c("var", "level", "N", "pos") + } allTermsDF <- do.call(rbind, allTerms) - colnames(allTermsDF) <- c("var", "level", "N", "pos") inds <- apply(allTermsDF[,1:2], 1, paste0, collapse="") # use broom again to get remaining required statistics