[Rd] Wish there were a "strict mode" for R interpreter. What about You?

peter dalgaard pdalgd at gmail.com
Sun Apr 10 18:18:09 CEST 2011


On Apr 10, 2011, at 15:10 , Duncan Murdoch wrote:

> On 11-04-09 9:22 PM, Spencer Graves wrote:
>> On 4/9/2011 6:12 PM, Duncan Murdoch wrote:
>>> On 11-04-09 7:02 PM, Spencer Graves wrote:
....
>>>> 
>>>>         "R CMD check" will give this message sometimes when I don't feel
>>>> it's appropriate.  For example, I define a data object ETB in a package,
>>>> then give that as the default in a function call like
>>>> f(data.=ETB){if(missing(data.))data(ETB);  data.}.  When I run "R CMD
>>>> check", I get "no visible binding for global variable 'ETB'", even
>>>> though the function is tested and works during R CMD check.
>>> 
>>> What is ETB?  Your code is looking for a global variable by that name,
>>> and that's what codetools is telling you.
>> 
>> Duncan:  Thanks for the question.
>> 
>> 
>> ETB is a data object in my package.  codetools can't find it because
>> data(ETB) is needed before ETB becomes available.  codetools is not
>> smart enough to check to see if ETB is a data object in the package.
> 
> Okay, I understand what you are trying to do.  Yes, you have fooled codetools in this instance.

...but notice that the codetools warning is just that: It _is_ acknowledged that these things occasionally happen by design. There are a couple of cases in base R too:

* checking R code for possible problems ... NOTE
glm.fit: no visible binding for global variable ‘n’
quantile.ecdf: no visible binding for global variable ‘y’

I can't seem to spot the 'n' just now, though...

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-devel mailing list