[R-pkg-devel] Trying to work around missing functionality

J C Nash profjcn@@h @ending from gm@il@com
Tue Aug 28 02:44:22 CEST 2018


Unfortunately, makes things much worse. I'd tried something like this already.

> * checking examples ... ERROR
> Running examples in ‘rootoned-Ex.R’ failed
> The error most likely occurred in:
> 
>> ### Name: rootwrap
>> ### Title: zeroin: Find a single root of a function of one variable within
>> ###   a specified interval.
>> ### Aliases: rootwrap
>> ### Keywords: root-finding
>> 
>> ### ** Examples
>> 
>> # Dekker example
>> # require(rootoned)
>> dek <- function(x){ 1/(x-3) - 6 }
>> r1 <- rootwrap(dek, ri=c(3.0000001, 6), ftrace=TRUE, method="uniroot")
> Error in registerNames(names, package, ".__global__", add) : 
>   The namespace for package "rootoned" is locked; no changes in the global variables list may be made.
> Calls: rootwrap -> TraceSetup -> <Anonymous> -> registerNames
> Execution halted

Also had to use utils::globalVariables( ...

JN


On 2018-08-27 08:40 PM, Richard M. Heiberger wrote:
> Does this solve the problem?
> 
> if (getRversion() >= '2.15.1')
>   globalVariables(c('envroot'))
> 
> I keep this in file R/globals.R
> 
> I learned of this from John Fox's use in Rcmdr.
> 
> On Mon, Aug 27, 2018 at 8:28 PM, J C Nash <profjcnash using gmail.com> wrote:
>> In order to track progress of a variety of rootfinding or optimization
>> routines that don't report some information I want, I'm using the
>> following setup (this one for rootfinding).
>>
>> TraceSetup <- function(ifn=0, igr=0, ftrace=FALSE, fn=NA, gr=NA){
>> # JN: Define globals here
>>    groot<-list(ifn=ifn, igr=igr, ftrace=ftrace, fn=fn, gr=gr, label="none")
>>    envroot <<- list2env(groot) # Note globals in FnTrace
>>    ## This generates a NOTE that
>>    ## TraceSetup: no visible binding for '<<-' assignment to ‘envroot’
>> ##   envroot<-list2env(groot, parent=.GlobalEnv) # Note globals in FnTrace -- this does NOT work
>>    ## utils::globalVariables("envroot") # Try declaring here -- causes errors
>> # end globals
>>    envroot
>> }
>>
>> FnTrace <- function(x,...) {
>>   # Substitute function to call when rootfinding
>>   # Evaluate fn(x, ...)
>>     val <- envroot$fn(x, ...)
>>     envroot$ifn <- envroot$ifn + 1 # probably more efficient ways
>>     if (envroot$ftrace) {
>>        cat("f(",x,")=",val," after ",envroot$ifn," ",envroot$label,"\n")
>>     }
>>     val
>> }
>>
>>
>> Perhaps there are better ways to do this, but this does seem to work quite well.
>> It lets me call a rootfinder with FnTrace and get information on evaluations of fn().
>> (There's another gr() routine, suppressed here.)
>>
>> However, R CMD check gives a NOTE for
>>
>>   TraceSetup: no visible binding for global variable ‘envroot’
>>   Undefined global functions or variables:
>>     envroot
>>
>> The commented lines in TraceSetup suggest some of the things I've tried. Clearly I don't
>> fully comprehend how R is grinding up the code, but searches on the net seem to indicate
>> I am far from alone. Does anyone have any suggestion of a clean way to avoid the NOTE?
>>
>> JN
>>
>> ______________________________________________
>> R-package-devel using r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-package-devel



More information about the R-package-devel mailing list