What I think we need is the number of rows of the model frame *before subsetting*, so that any further arguments (and there are none such in Martin's example) of the same length as the response get subsetted.
Berwin's fix is ugly, and I think it can be avoided by using model.frame to do the work by manipulating ... rather carefully so e.g. col gets read from the model frame and hence subsetted -- that would also allow col to be written in terms of other variables in the model frame. I need to spend more time thinking about this in detail. Brian On Mon, 8 Mar 2004 [EMAIL PROTECTED] wrote: > >>>>> "BeT" == Berwin A Turlach <[EMAIL PROTECTED]> > >>>>> on Mon, 8 Mar 2004 09:17:51 +0100 (CET) writes: > > BeT> Dear all, I noticed the following bug in points.formula > > <...> > BeT> Error in if (length(x) == l) x[s] else x : argument is > BeT> of length zero > > Thank you, Berwin. > The bug is still present in current "R-1.9.0 alpha" > and can be demonstrated with the slightly simpler code > > roller <- > data.frame(weight = c(1.9, 3.1, 3.3, 4.8, 5.3, 6.1, 6.4, 7.6, 9.8, 12.4), > depression = c(2, 1, 5, 5, 20, 20, 23, 10, 30, 25)) > plot( depression ~ weight, data=roller, type="n") > with(roller, points( depression~weight, subset=1:7 )) # ok > with(roller, points( depression~weight, subset=8:10)) # ok > with(roller, points( depression~weight, subset=8:10, col=2))## --> Error > > BeT> This seems to be due to the fact that the data used was > BeT> attached before the call and not specified in the call > BeT> via the "data" argument. > > Yes, using "data =" doesn't show the problem, > but as you see, the problem also shows for the more recommended > way of using with() instead of attach().. > > BeT> The following patch seems to fix the problem. > > *** /home/berwin/lang/R/Courses/3S6/plot.R.orig Tue Sep 2 23:43:42 2003 > --- /home/berwin/lang/R/Courses/3S6/plot.R Mon Mar 8 16:06:32 2004 > *************** > *** 312,318 **** > mf <- eval(m, parent.frame()) > if (!missing(subset)) { > s <- eval(m$subset, data, parent.frame()) > ! l <- nrow(data) > dosub <- function(x) if (length(x) == l) x[s] else x > dots <- lapply(dots, dosub) > } > --- 312,320 ---- > mf <- eval(m, parent.frame()) > if (!missing(subset)) { > s <- eval(m$subset, data, parent.frame()) > ! mtmp <- m > ! mtmp$subset <- NULL > ! l <- nrow(eval(mtmp, parent.frame())) > dosub <- function(x) if (length(x) == l) x[s] else x > dots <- lapply(dots, dosub) > } > > ------------------- > > Yes, but the resulting code becomes even more ugly. > doing a second eval(m, ..) just with a slightly modified 'm'... > > Though I'll have to leave it to others to find if there is a > better patch... > > Thanks again, Berwin! > Martin > > ______________________________________________ > [EMAIL PROTECTED] mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-devel > > -- Brian D. Ripley, [EMAIL PROTECTED] 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 ______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-devel