Thanks for your answer. Should I report in Bugzilla at least so it's tracked?
I can point that the issue is with line 6 of the function body: ``` dots <- lapply(m$..., eval, md, eframe) ``` I assume the intention was to evaluate the arguments with the context of data passed to the function. But the expression in panel.first / panel.last gets evaluated before plot.new is called (as the error indicates). I believe the fix would be to somehow not evaluate line 6, or replace with `dots <- m$...`, and when `plot` is later called, to somehow evaluate it with the data passed to the function. I tried to add `envir` argument to `do.call` but it does not work as I expected. I would've liked to contribute a patch but my R knowledge is limited and and this `plot.formula` code is a bit of my head frankly. Kindly, Erez On Sat, Jul 6, 2024, at 1:05 AM, Duncan Murdoch wrote: > That definitely looks like a bug, but not one that anyone will be eager > to fix. It's very old code that tried to be clever, and that's the > hardest kind of code to fix. > > Remember Kernighan's Law: "Everyone knows that debugging is twice as > hard as writing a program in the first place. So if you’re as clever as > you can be when you write it, how will you ever debug it?" > > Duncan Murdoch > > On 2024-07-05 7:35 a.m., Erez Shomron wrote: > > Is the following a bug in your opinion? I think so. > > > > This works as expected: > > > > ``` > > with(mtcars, plot(wt, mpg, plot.first = { > > plot.window(range(wt), range(mpg)) > > arrows(3, 15, 4, 30) > > })) > > ``` > > > > This does not. > > > > ``` > > plot(mpg ~ wt, data = mtcars, plot.first = { > > plot.window(range(wt), range(mpg)) > > arrows(3, 15, 4, 30) > > }) > > ``` > > > > With error: > > ``` > > Error in arrows(3, 15, 4, 30) : plot.new has not been called yet > > ``` > > > > The second example should work. > > > > From the docs: > > > > ?plot.formula > > " For the ‘plot’ method the formula can be of the form ‘~ z + y + > > z’: the variables specified on the right-hand side are collected > > into a data frame, subsetted if specified, and displayed by > > ‘plot.data.frame’. > > " > > > > ?plot.data.frame > > " ...: further arguments to ‘stripchart’, ‘plot.default’ or ‘pairs’. > > " > > > > And plot.default has both plot.first and plot.last > > > > It seems very arbitrary you can't use these parameters with the > > plot.formula method specifically. > > > >> sessionInfo() > > R version 4.4.1 (2024-06-14) > > Platform: x86_64-suse-linux-gnu > > Running under: openSUSE Tumbleweed > > [...] > > > > ______________________________________________ > > R-help@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. > > ______________________________________________ R-help@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.