[Rd] backquotes and term.labels

Therneau, Terry M., Ph.D. therneau at mayo.edu
Mon Mar 5 21:55:30 CET 2018


A user reported a problem with the survdiff function and the use of variables that contain 
a space.  Here is a simple example.  The same issue occurs in survfit for the same reason.

lung2 <- lung
names(lung2)[1] <- "in st"   # old name is inst
survdiff(Surv(time, status) ~ `in st`, data=lung2)
Error in `[.data.frame`(m, ll) : undefined columns selected

In the body of the code the program want to send all of the right-hand side variables 
forward to the strata() function.  The code looks more or less like this, where m is the 
model frame

   Terms <- terms(m)
   index <- attr(Terms, "term.labels")
   if (length(index) ==0)  X <- rep(1L, n)  # no coariates
   else X <- strata(m[index])

For the variable with a space in the name the term.label is "`in st`", and the subscript 
fails.

Is this intended behaviour or a bug?  The issue is that the name of this column in the 
model frame does not have the backtics, while the terms structure does have them.

Terry T.



More information about the R-devel mailing list