[R-pkg-devel] Visible bindings and reference classes

William Dunlap wdunlap at tibco.com
Tue Aug 11 18:04:27 CEST 2015


You can avoid the temporary file by replacing
  dput(def, file= (tf <- tempfile()))
  compiler::cmpfile(tf)
with
  cdef <- compiler::compile(def)
  #Note: no visible binding for '<<-' assignment to 'ConfigString'
The compiled code appears to work.
  eval(cdef)
  c1 <- Config$new()
  c1
  #Reference class object of class "Config"
  #Field "ConfigString":
  #[1] "Hello, World!"
  > objects(all=TRUE)
  #[1] ".__C__Config"           ".__global__"
  #[3] ".requireCachedGenerics" "c1"
  #[5] "cdef"                   "Config"
  #[7] "def"


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Tue, Aug 11, 2015 at 8:47 AM, William Dunlap <wdunlap at tibco.com> wrote:

> This is a problem in the compiler package.  Here is a way to reproduce it:
>
> def <- quote(Config <- setRefClass("Config",
>     fields = list(
>         ConfigString = "character"),
>     methods = list(
>         # Constructor
>         initialize = function() {
>             ConfigString <<- "Hello, World!"
>         })
> ))
> dput(def, file= (tf <- tempfile()))
> compiler::cmpfile(tf)
> #Note: no visible binding for '<<-' assignment to 'ConfigString'
> saving to file
> #"C:\Users\wdunlap\AppData\Local\Temp\Rtmpk91qvT\file26d447c45b81.Rc" ...
> done
>
>
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> On Tue, Aug 11, 2015 at 4:24 AM, Martin Maechler <
> maechler at stat.math.ethz.ch> wrote:
>
>> >>>>> Colin Gillespie <csgillespie at gmail.com>
>> >>>>>     on Mon, 10 Aug 2015 20:33:32 +0000 writes:
>>
>> > Dear All,
>> >
>> > I have a package that uses reference classes. When I build the package I
>> > get numerous notes of the sort
>> >
>> > Note: no visible binding for '<<-' assignment to 'pars'
>> >
>> > I've tried using GlobalVariables, but that didn't solve the issue.
>>
>> [ You mean globalVariables(): and it's a bad idea anyway IMO,
>>   even if it is recommended : If you declare a variable in
>>   there, it is "global" in all places in your package and the
>>   codetools won't report it anywhere anymore.
>>   Much better in my view is to use something like
>>
>>   var7 <- NULL # ~= globalVariables("var7")
>>
>> ]
>>
>> To your question:
>>
>> Reference classes are used in *many* places,  and the use of  ' <<- '
>> is really "standard" there.
>> e.g., package 'lme4', or 'pcalg' are two packages I'm involved with,
>> which use ref.classes and ' <<- '  but are "fine" with that.
>>
>> So there must be something peculiar in your package leading to
>> the  <<-  warnings.
>>
>> Maybe you should look into the source code of such other CRAN
>> packages to see how "they" do it differently than you.
>>
>> Best regards,
>> Martin
>>
>> Martin Maechler, ETH Zurich
>>
>>
>> > After some googling, I came across the page
>> > http://stackoverflow.com/q/23475309/203420 which suggests
>> >
>> > suppressBindingNotes <- function(variablesMentionedInNotes) {
>> >   for(variable in variablesMentionedInNotes) {
>> >     assign(variable,NULL, envir = .GlobalEnv)
>> >   }
>> > }
>> > suppressBindingNotes(c("dat", "internal", "xmin", "pars", "no_pars"))
>> >
>> > But checking the package with --as-cran raises the note
>> >
>> > * checking R code for possible problems ... NOTE
>> > Found the following assignments to the global environment:
>> >   File ‘poweRlaw/R/aaa_all_classes.R’:
>> >   assign(variable, NULL, envir = .GlobalEnv)
>> >
>> > What is the correct way of removing the "visible bindings" notes?
>> >
>> > Thanks
>> >
>> > Colin
>> >
>> >       [[alternative HTML version deleted]]
>> >
>> > ______________________________________________
>> > R-package-devel at r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-package-devel
>>
>> ______________________________________________
>> R-package-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>>
>
>

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list