From ripley at stats.ox.ac.uk  Fri Oct 12 20:13:26 2007
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Fri, 12 Oct 2007 19:13:26 +0100 (BST)
Subject: [Rd] no visible binding
In-Reply-To: <470FA90F.8000503@statistik.uni-dortmund.de>
References: <050851DE-BDC9-4F82-8EA9-B05B9DC60AA7@uiuc.edu>
	<Pine.LNX.4.64.0710121855510.17956@reclus.nhh.no>
	<470FA90F.8000503@statistik.uni-dortmund.de>
Message-ID: <Pine.LNX.4.64.0710121908150.21896@gannet.stats.ox.ac.uk>

Just to pick on this: 'how to react?'.

Codetools does have false positives, and non-standard evaluation often 
triggers them.  I've seen this one several times and pretty clearly a 
chararcter string is better style.

But some are just false positives, including those in MASS.


On Fri, 12 Oct 2007, Uwe Ligges wrote:

>
>
> Roger Bivand wrote:
>> On Fri, 12 Oct 2007, roger koenker wrote:
>>
>>> Could someone advise me about how to react to the message:
>>>
>>> * checking R code for possible problems ... NOTE
>>> slm: no visible binding for global variable 'response'
>>>
>>> from R CMD check SparseM    with
>>> * using R version 2.6.0 Under development (unstable) (2007-09-03 r42749)
>>>
>>> The offending code looks like this:
>>>
>>> "slm" <-
>>> function (formula,  data, weights, na.action, method = "csr",
>>>     contrasts = NULL, ...)
>>> {
>>>     call <- match.call()
>>>     m <- match.call(expand.dots = FALSE)
>>>     m$method <- m$model <- m$x <- m$y <- m$contrasts <-  m$... <- NULL
>>>     m[[1]] <- as.name("model.frame")
>>>     m <- eval(m, sys.frame(sys.parent()))
>>>     if (method == "model.frame")
>>>         return(m)
>>>     Terms <- attr(m, "terms")
>>>     weights <- model.extract(m, weights)
>>>     Y <- model.extract(m, response)
>>                              ^^^^^^^^
>>
>> which becomes:
>>
>>> as.character(substitute(response))
>> [1] "response"
>>
>> inside model.extract. I'm not sure why codetools doesn't pick up weights
>> in the same context one line earlier, probably because weights is also
>> assigned to.
>
> Yes. That object exists, but response does not.

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



[Rd] no visible binding
Prof Brian Ripley