Search code examples
r

R ggforest(): Error in match.names(clabs, names(xi)): names do not match previous names


I just updated R to version 4.2.2 and RStudio to version 2022.12.0+353 and now when I run ggforest() on my Cox model, I get a name match error (shown below).

This is while this exact code was working perfectly prior to the updates. Has anyone else faced such error or know how to fix it?

I'm using a Mac M1, OS version 12.5.1.

cx1 <- coxph(Surv(surv_time, surv_status) ~ mygrp + age + sex + educ, data =mydata)
ggforest(cx1, data = mydata)

**Error in match.names(clabs, names(xi)) :
names do not match previous names**

Note that when I run a univariate cox model with any single one of the covariates alone, ggforest() works error-free. But as soon as there is more than one coviariate in the cox model, ggforest() throws the above error.


Solution

  • I encountered the same issue as you. I solved this by converting my data table from a tibble to standard R data.frame using the as.data.frame function. For example

    cx1 <- coxph(Surv(surv_time, surv_status) ~ mygrp + age + sex + educ, data = as.data.frame(mydata)) 
    

    Cheers!