[Rd] issue with [[<-Call

Terry Therneau therneau at mayo.edu
Thu Dec 25 23:27:31 CET 2008


  The following code works in Splus but not in R

coxph <- function(formula, data, weights, subset, na.action,
	init, control, method= c("efron", "breslow", "exact"),
	singular.ok =TRUE, robust=FALSE,
	model=FALSE, x=FALSE, y=TRUE, ...) {

    method <- match.arg(method)
    Call <- match.call()

    # create a call to model.frame() that contains the formula (required)
    #  and any other of the relevant optional arguments
    # then evaluate it in the proper frame
    temp <- call('model.frame', formula=formula)
    for (i in c("data", "weights", "subset", "na.action")) #add optional args
        if (!is.null(Call[[i]])) temp[[i]] <- Call[[i]]

    if (is.R()) m <- eval(temp, parent.frame())
    else        m <- eval(temp, sys.parent())

---------------------------------

 The problem is that the names ('data', 'weights', etc) do no propogate over
to temp, the new call object.  It looks like an oversight in the replacement 
method.

  Priority: low.  I have other code forms that work in both dialets.
 
  I created this when teaching an internal class on S programming; the goal
was to make what was happening as transparent as possible.  If anyone has
something that they think is even better from a teaching point of view I'd
be delighted to see it.

	Terry T.



More information about the R-devel mailing list