[R] warning on generic function when building R package
David Stevens
david.stevens at usu.edu
Tue Oct 27 20:52:42 CET 2015
Sorry to be a late comer to this problem but I'm having a similar
issue. My function is called by ode from deSolve
ADM1_C <- function(t,state,parameters,...){
with(as.list(c(state,parameters)), {
# do some stuff here and return a list containing a vector of
derivatives to ode
...
})
}
in which 't' is a time and 'state' and 'parameters' are numeric vectors
with each element named. When I invoke the solver,
times <- d.df$time
out <- as.data.frame(ode(y = state,times = times,func = ADM1_C,parms =
parameters))
I get ~three Note:s for each value in 'state' (sometimes more). The
calculation is successful but the issue is a little puzzling.
Here's 'state'
state
Ssu Saa Sfa Sva Sbu Spro Sac Sh2
Sch4 Sic
0.300000 0.001000 0.300000 0.300000 0.300000 0.300000 0.300000 0.000001
0.000010 0.040000
Sin Si Xc Xch Xpr Xli Xsu Xaa
Xfa Xc4
0.010000 0.020000 0.300000 0.026000 0.300000 0.030000 0.400000 1.100000
0.200000 0.410000
Xpro Xac Xh2 Xi Scation Sanion Sva_m Sbu_m
Spro_m Sac_m
0.137000 0.700000 0.010000 5.000000 0.040000 0.020000 0.090000 0.090000
0.074000 0.169000
Shco3_m Snh3 Sgas_h2 Sgas_ch4 Sgas_co2
0.009700 0.016000 0.020000 0.020000 0.037600
The messages are something like this ...
Note: no visible binding for global variable 'Sin'
Note: no visible binding for global variable 'Snh3'
Note: no visible binding for global variable 'Scation'
Note: no visible binding for global variable 'Shco3_m'
.... (~130 rows of these messages)
Neither Duncan's nor Jim's solution solved the problem. I can't change
(at least I don't think so) how ode(...) calls the function except via
the documentation. Any ideas? Does it matter? Could it be ode strips out
the names, but only sometimes?
signed Grasping at Straws (David)
David K Stevens, P.E., Ph.D.
Professor and Head, Environmental Engineering
Civil and Environmental Engineering
Utah Water Research Laboratory
8200 Old Main Hill
Logan, UT 84322-8200
435 797 3229 - voice
435 797 1363 - fax
david.stevens at usu.edu
On 10/19/2015 2:32 PM, carol white via R-help wrote:
> In effect, this works
> but whether I use x or x.init, y or y.init in plot.func, I get
>
> no visible binding for global variable ‘x.init’no visible binding for global variable ‘y.init’
> Regards,
>
> On Monday, October 19, 2015 9:59 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>
>
> On 19/10/2015 3:50 PM, carol white wrote:
>> Thanks Murdoch.
>>
>> defining
>> plot.func<- function(x=x.init, y=y.init, arg3, arg4, "title", col, arg5)
>>
>> and if plot doesn't take the exact parameters of plot.func but modified
>> of these parameters
>> plot(x=x.pt,y=y.pt,xlim = c(0, 10), ylim = c(0,1), xlab= "xlab",
>> ylab="ylab", main = "title", col = col,type = "l")
>>
>> then, how to define and invoke to be consisent?
> I don't really understand your question, but this is all about the
> function header for plot.func, not the call you make to plot(). You
> need to name the first argument as "x", you need to include "..." as an
> open argument, and you need a legal header. So this would be okay:
>
>
> plot.func<- function(x=x.init, y=y.init, arg3, arg4,
> main = "title", # can't skip the arg name
> col, arg5,
> ...) { # can't skip the dots
>
> Duncan Murdoch
>
>> Regards,
>>
>> On Monday, October 19, 2015 7:45 PM, Duncan Murdoch
>> <murdoch.duncan at gmail.com> wrote:
>>
>>
>> On 19/10/2015 1:29 PM, carol white via R-help wrote:
>>
>>> Hi,I have invoked plot in a function (plot.func) as follows but when I
>> check the built package, I get a warning:
>>> plot(x.pt,y.pt,xlim = c(0, 10), ylim = c(0,1), xlab= "xlab",
>> ylab="ylab", main = "title", col = col,type = "l")
>>> R CMD check my.package
>>> checking S3 generic/method consistency ... WARNING
>>> plot:
>>> function(x, ...)
>>> plot.func:
>>> function(x.pt, y.pt, arg3, arg4, "title", col, arg5)
>>>
>>> See section ‘Generic functions and methods’ in the ‘Writing R
>>> Extensions’ manual.
>>> Which plot argument is illegitimate or missing and how to eliminate
>> the warning?
>>
>>
>> The first argument to plot.func needs to be called "x" if you want to
>> use it as a method. Method signatures need to be consistent with the
>> generic signature.
>>
>> Duncan Murdoch
>>
>>
>>
>>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list