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 parametersplot(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? 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]]
Duncan Murdoch
2015-Oct-19 19:59 UTC
[R] warning on generic function when building R package
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 > > > >
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]]
What is the class attribute of your (misnamed) x.pt argument? If it does not inherit from class "func" then your plot.func method will not be used when you call plot(). You would need to explicitly call plot.func() instead. If this question/comment makes no sense to you, then you have some serious homework to do before you post further. Otherwise, follow the advice you have been given. Bert On Monday, October 19, 2015, carol white via R-help <r-help at r-project.org> 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 parametersplot(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? > Regards, > > On Monday, October 19, 2015 7:45 PM, Duncan Murdoch < > murdoch.duncan at gmail.com <javascript:;>> 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 <javascript:;> 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.-- Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll [[alternative HTML version deleted]]