[Rd] issue with [[<-Call

Charles C. Berry cberry at tajo.ucsd.edu
Fri Dec 26 00:06:45 CET 2008


On Thu, 25 Dec 2008, Terry Therneau wrote:

>  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.


        if (!is.null(Call[[i]])) temp[ i ] <- Call[[i]]

should do it in R at least.

HTH,

Chuck


>
>  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.
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901



More information about the R-devel mailing list