Using the compiler package and suppressing "No visible binding for a global variable"

I use R 3.0.2 on Ubuntu 14. I do some heavy computing in my code, and I tried the “compiler” package with

compilePKGS(enable=TRUE) enableJIT(3) 

And it seems to speed up my code. Very nice!

But every time my package allows the "compiler", I get a lot of notes, for example

 Note: no visible binding for global variable '.Data' 

or something similar with my own S4 objects (its "obj @result" in code):

 Note: no visible binding for global variable 'result' 

which is, for example, part of a makeshift object S4. Adding setCompilerOptions("suppressAll", TRUE) or setCompilerOptions("suppressUndefined", TRUE) did not help. When I completely deactivate the compiler package, no notes appear at all, so this may be a problem with my understanding of the compiler-package / jit?

What can I do to suppress these notes?

Edit:

 require(compiler) compilePKGS(enable=TRUE) enableJIT(3) setClass(Class = "testobject", slots = c( data = "numeric", test = "character", split = "numeric", name = "character" ) ) a <- new("testobject", data=c(1,2,3,4), test="TEST", split=5, name="NAME") for(i in a@data ){ print(i) } 

A simple example gives

 Note: no visible binding for global variable '.Data' Note: no visible binding for global variable '.Data' 

immediately after calling ClassDefinition

+7
r package
source share
2 answers

You can suppress these notes from R using

setCompilerOptions(suppressAll = TRUE)

There is no need to suppress the "undefined" options separately, which will suppress "everything." In addition, you can set the environment variable

export R_COMPILER_SUPPRESS_ALL=true (or similar in different OSs).

If you want to prevent only the compiler from warning about variables that are or seem undefined, you can do

setCompilerOptions(suppressUndefined=TRUE)

And if you want to do this only for the .Data variable, you can do

setCompilerOptions(suppressUndefined=".Data") .

Note that there is no need to enable package compilation when you use the compiler to speed up your code, all you need to do is enable JIT. You can do this from R, as in your example, or just set another variable

export R_ENABLE_JIT=3

To enable the most aggressive optimizations, you can also customize

export R_COMPILER_OPTIMIZE=3

or from R run setCompilerOptions(optimize=3)

When you enable JIT compilation through an environment variable, you do not need to explicitly load the compiler package - this will be done automatically.

+7
source share

You can define a global variable using, for example,

 utils::globalVariables(".Data") 

This will prevent the "lack of visible binding for the global variable" NOTE.

This takes precedence over suppressing the entire compiler message that it targets; You will not suppress other useful compiler messages.

+3
source share

All Articles