[Rd] R CMD check tells me 'no visible binding for global variable ', what does it mean?

2010-04-12 Thread Michael Dewey
When I run R CMD check on a package I have recently started work on I 
get the following:


* checking R code for possible problems ... NOTE
addlinear: no visible binding for global variable 'x'

I appreciate that this is only a NOTE and so I assume is R's 
equivalent of 'This is perfectly legal but I wonder whether it is 
really what you intended' but I would like to understand it.


In the relevant function addlinear the following function is defined locally:

   orfun - function(x, oddsratio) {1/(1+1/(oddsratio * (x/(1-x}

and then used later in curve

  curve(orfun(x, exp(estimate)), from = 0.001, to = 0.999, add = TRUE)

These are the only occurrences of 'x'.

Is it just telling me that I have never assigned a value to x? Or is 
it more sinister than that? As far as I can tell the function does 
what I intended.



Michael Dewey
http://www.aghmed.fsnet.co.uk

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] R CMD check tells me 'no visible binding for global variable ', what does it mean?

2010-04-12 Thread Duncan Murdoch

On 12/04/2010 10:51 AM, Michael Dewey wrote:
When I run R CMD check on a package I have recently started work on I 
get the following:


* checking R code for possible problems ... NOTE
addlinear: no visible binding for global variable 'x'

I appreciate that this is only a NOTE and so I assume is R's 
equivalent of 'This is perfectly legal but I wonder whether it is 
really what you intended' but I would like to understand it.


In the relevant function addlinear the following function is defined locally:

orfun - function(x, oddsratio) {1/(1+1/(oddsratio * (x/(1-x}

and then used later in curve

   curve(orfun(x, exp(estimate)), from = 0.001, to = 0.999, add = TRUE)

These are the only occurrences of 'x'.

Is it just telling me that I have never assigned a value to x? Or is 
it more sinister than that? As far as I can tell the function does 
what I intended.


The curve() function evaluates the first argument in a strange way, and 
this confuses the code checking.  (The variable name x is special to 
curve().)


I think you can avoid the warning by rewriting that call to curve() as

curve(function(x) orfun(x, exp(estimate)), from = 0.001, to = 0.999, add = TRUE)

Duncan Murdoch

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] R CMD check tells me 'no visible binding for global variable ', what does it mean?

2010-04-12 Thread Henrik Bengtsson
On Mon, Apr 12, 2010 at 5:08 PM, Duncan Murdoch murd...@stats.uwo.ca wrote:
 On 12/04/2010 10:51 AM, Michael Dewey wrote:

 When I run R CMD check on a package I have recently started work on I get
 the following:

 * checking R code for possible problems ... NOTE
 addlinear: no visible binding for global variable 'x'

 I appreciate that this is only a NOTE and so I assume is R's equivalent of
 'This is perfectly legal but I wonder whether it is really what you
 intended' but I would like to understand it.

 In the relevant function addlinear the following function is defined
 locally:

    orfun - function(x, oddsratio) {1/(1+1/(oddsratio * (x/(1-x}

 and then used later in curve

       curve(orfun(x, exp(estimate)), from = 0.001, to = 0.999, add = TRUE)

 These are the only occurrences of 'x'.

 Is it just telling me that I have never assigned a value to x? Or is it
 more sinister than that? As far as I can tell the function does what I
 intended.

 The curve() function evaluates the first argument in a strange way, and this
 confuses the code checking.  (The variable name x is special to curve().)

 I think you can avoid the warning by rewriting that call to curve() as

 curve(function(x) orfun(x, exp(estimate)), from = 0.001, to = 0.999, add =
 TRUE)

...or

x - NULL; rm(x); # Dummy to trick R CMD check
curve(orfun(x, exp(estimate)), from = 0.001, to = 0.999, add = TRUE)

/Henrik


 Duncan Murdoch

 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel


__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel