7

I'm using R 3.0.2 on Ubuntu 14. I make some heavy calculations in my code, and I tried out the "compiler" package with

compilePKGS(enable=TRUE)
enableJIT(3)

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

But everytime my package enables the "compiler", I get a lot of notes like

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

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

Note: no visible binding for global variable 'result'

which is, for example, part of a self-made S4 object. Adding setCompilerOptions("suppressAll", TRUE) or setCompilerOptions("suppressUndefined", TRUE)didn't help. When I deactivate the compiler package completely, no notes pop up at all, so this might 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)
}

Simple example produces

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

directly after the ClassDefinition Call

Marc
  • 238
  • 1
  • 9
  • You can hide such notes if you define `.Data` (e.g. add `.Data <- NULL` at the beginning of your script). I'm not totally sure why it's issued here, so maybe someone else can confirm that this is a save thing to do. – Paul Staab Jun 17 '14 at 10:29
  • Yeah, thats true, I found a similar answer in [link](http://stackoverflow.com/a/23476834/2720455) , but the funny thing is, that these messages don't appear, when I deactivate the compiler, or the jit(3). The workaround in the linked thread creates variables in the environment. I don't think thats appropiate for a package? This feels compiler related or am I missing something? Thanks for your help! :) – Marc Jun 18 '14 at 07:46
  • 1
    @Marc Did you by any chance found a solution? – Adam Ryczkowski Aug 04 '16 at 05:13
  • I'm having the same issue with the compiler package, it came out of left field while using it in a Spark pipe() situation and I've been unable to find any solutions. – the_skua Aug 29 '16 at 17:54

2 Answers2

7

You can suppress these notes from R using

setCompilerOptions(suppressAll = TRUE)

There is no need to separately suppress the "undefined" options, suppressing "all" will do. Alternatively, you can set up environment variable

export R_COMPILER_SUPPRESS_ALL=true (or similarly under different OSes).

If you wanted to suppress only warnings about variables that are or seem to be undefined to the compiler, you can do

setCompilerOptions(suppressUndefined=TRUE)

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

setCompilerOptions(suppressUndefined=".Data").

Note also there is no need to enable compilation of packages when you use compiler to speed up your code, all you need to do is enable the JIT. You can do it from R as in your example, or just setting another variable

export R_ENABLE_JIT=3

To enable most aggressive optimizations, you can also set up

export R_COMPILER_OPTIMIZE=3

or from R run setCompilerOptions(optimize=3)

When enabling JIT compilation via environment variable, you don't have to explicitly load the compiler package - it will be done automatically.

Tomas Kalibera
  • 1,061
  • 9
  • 13
  • Yes! Thank you. I'm surprised I hasn't seen the suppressAll = TRUE elsewhere, but this did the trick for me. – the_skua Aug 30 '16 at 19:03
  • Setting compiler options is covered in the manual (?setCompilerOptions), a new version of R will also have an example there to make it clearer. – Tomas Kalibera Aug 31 '16 at 14:41
3

You can define a global variable by using, for example

utils::globalVariables(".Data")

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

This has the advantage over of suppressing all compiler message that it is targetted; you won't suppress other, useful, compiler messages.

Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
  • 1
    If you want to suppress only this particular warning, the intended way to do that is via setCompilerOptions(suppressUndefined=".Data"). – Tomas Kalibera Aug 31 '16 at 14:35