[Rd] Bug report: 'formula("x")' loops infinitely ('formula("y")' does not)
Martin Maechler
m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Mon Jun 17 10:21:24 CEST 2019
>>>>> P Poncet via R-devel
>>>>> on Fri, 14 Jun 2019 19:56:14 +0000 writes:
> Dear,
> The script'formula("x")' loops infinitely.
well ... if it would really, your computer would still be
running and heating ... ;-)
> More specifically, it throws the following error:
> Error: evaluation nested too deeply: infinite recursion /
> options(expressions=)?
Yes, or something similar depending on your computer operating
system (OS) and/or memory settings.
> As a side effect,this makes an IDE like RStudio to crash.
[really ?]
> On the other hand,the script 'formula("y")' works as
> expected : if ‘y’ does not exist in the global environment,
> it throws:
> Error in eval(parse(text = x, keep.source = FALSE)[[1L]]) :
> object ‘y’ not found
well, that's not "as expected" I hope; also it should not depend
on "y" existing or not.
> I use R-3.6.0 on Windows.
Interestingly, when I had introduced str2lang() and
str2expression() into R-devel [now in R 3.6.0] I also made long
passes into all the base R code to find locations where these
new functions could & should be used... and also found the
formula.character method (in R base package 'stats') which is
indeed what formula("..") calls.
When trying to introduce str2call() etc there, I indeed found
that formula.character() had many quirks and undesired
properties *in the case* a user does not specify a formula
correctly. I've corrected all (well, modestly say "most") of
these, such in R-devel, for several months now,
> formula("x")
Error in formula.character("x") : invalid formula "x": not a call
> formula("y")
Error in formula.character("y") : invalid formula "y": not a call
>
{ which is something I would expect rather then the above
'object "y" not found' ...}
> Best regards, Paul Poncet
Thank you, Paul!
To other readers: I am tempted to port the new formula()
behavior from R-devel to R patched, to make it into R 3.6.1
It does fix this and similar bugs/inconsistencies but it *is* a minor
API change and may break user code that had relied on previous
incorrect behavior.
In R-devel, e.g.,
> formula(c("y~ ", " x"))
y ~ x
Warning message:
Using formula(x) is deprecated when x is a character vector of length > 1.
Consider formula(paste(x, collapse = " ")) instead.
> formula("{y ~ x}")
y ~ x
Warning message:
invalid formula "{y ~ x}": extraneous call to `{` is deprecated
>
and if we port formula.character() from R-devel to 'R patched'
(to become 3.6.1), we'd port it completely.
Opinions?
Martin Maechler
ETH Zurich and R Core team
More information about the R-devel
mailing list