From therneau at mayo.edu  Mon Mar  5 21:55:30 2018
From: therneau at mayo.edu (Therneau, Terry M., Ph.D.)
Date: Mon, 05 Mar 2018 14:55:30 -0600
Subject: [Rd] backquotes and term.labels
Message-ID: <fd55f7$90njgf@ironport10.mayo.edu>

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.



[Rd] backquotes and term.labels
Therneau, Terry M., Ph.D.