Camford Oxbridge
Camford Oxbridge

Reputation: 894

A note on graphics::curve() in R CMD check

I use the following code in my own package.

 graphics::curve( foo (x) )

When I run R CMD check, it said the following note.How do I delete the NOTE?

> checking R code for possible problems ... NOTE
  foo: no visible binding for global variable 'x'
  Undefined global functions or variables:
    x

Edit for the answers:

I try the answer as follows.

function(...){
   utils::globalVariables("x")
   graphics::curve( sin(x) )
}

But it did not work. So,..., now, I use the following code, instead

function(...){
   x <-1 # This is not used but to avoid the NOTE, I use an object "x".
   graphics::curve( sin(x) )
}

The last code can remove the NOTE.

Huuum, I guess, the answer is correct, but, I am not sure but it dose not work for me.

Upvotes: 0

Views: 41

Answers (1)

r2evans
r2evans

Reputation: 160447

Two things:

  1. Add

    utils::globalVariables("x")
    

    This can be added in a file of its own (e.g., globals.R), or (my technique) within the file that contains that code.

    It is not an error to include the same named variables in multiple files, so the same-file technique will preclude you from accidentally removing it when you remove one (but not another) reference. From the help docs: "Repeated calls in the same package accumulate the names of the global variables".

    This must go outside of any function declarations, on its own (top-level). While it is included in the package source (it needs to be, in order to have an effect on the CHECK process), but otherwise has no impact on the package.

  2. Add

    importFrom(utils,globalVariables)
    

    to your package NAMESPACE file, since you are now using that function (unless you want another CHECK warning about objects not found in the global environment :-).

Upvotes: 1

Related Questions