From therneau at mayo.edu  Thu Dec 25 23:27:31 2008
From: therneau at mayo.edu (Terry Therneau)
Date: Thu, 25 Dec 2008 16:27:31 -0600 (CST)
Subject: [Rd] issue with [[<-Call
Message-ID: <200812252227.mBPMRV2a029495@rocky.mayo.edu>

  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.



[Rd] issue with [[<-Call
Terry Therneau