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

luke-tierney at uiowa.edu luke-tierney at uiowa.edu
Tue Aug 11 20:47:03 CEST 2015


On Tue, 11 Aug 2015, Colin Gillespie wrote:

>>>> 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.
>>
>
> After a bit more investigating I've narrowed it down.  The notes can be
> generated by having
>
> d1 = setRefClass("d1", fields=list(x = "numeric"))
> d1$accessors("x")
>
> **and** having ByteCompile: true. Commenting out the accessors line removes
> the visible binding note. The  x=NULL  or globalVariables("x") trick
> doesn't work.

For now I would recommend not enabling byte code compilation or not
using accessors if you want to avoid these warnings. The compiler
notes are valid given the implementation of the accessors mechanism;
I'm fairly sure some minor changes to the accessor mechanism could
address this. We'll look into this.

Best,

luke

>
> A stackoverflow answer suggests that I need to add
>
> assign(variable,NULL, envir = .GlobalEnv)
>
> but this generates a new NOTE under R CMD check
>
> I've not been able to find another package that uses accessors and
> ByteCompile
>
> Thanks
>
> Colin
>
>
>
>
>
>
>
>
>
>
>>
>> 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
>>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-package-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel

-- 
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   luke-tierney at uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu


More information about the R-package-devel mailing list