[Rd] issue with [[<-Call
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Dec 26 09:30:50 CET 2008
The issue is that you are using [["weights"]] to add an element. It works
for existing eleents as well as for [<- and $<-.
However, I would have done this without a loop
nm <- c("data", "weights", "subset", "na.action")
extras <- nm %in% names(Call)
temp[ nm[extras] ] <- Call[extras]
which will also handle adding NULL elements correctly.
And BTW, the (current) R idiom is to use eval.parent(), and lm() shows
another way to do this that I would see as cleaner.
On Thu, 25 Dec 2008, Charles C. Berry wrote:
> 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
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-devel
mailing list