[Rd] codetools wrongly complains about lazy evaluation in S4 methods
Kasper Daniel Hansen
k@@perd@n|e|h@n@en @end|ng |rom gm@||@com
Tue Jun 13 20:03:08 CEST 2023
On Sat, Jun 3, 2023 at 11:51 AM Mikael Jagan <jaganmn2 using gmail.com> wrote:
> The formals of the newly generic 'qr.X' are inherited from the non-generic
> function in the base namespace. Notably, the inherited default value of
> formal argument 'ncol' relies on lazy evaluation:
>
> > formals(qr.X)[["ncol"]]
> if (complete) nrow(R) else min(dim(R))
>
> where 'R' must be defined in the body of any method that might evaluate
> 'ncol'.
>
Perhaps I am misunderstanding something, but I think Mikael's expectations
about the scoping rules of R are wrong. The enclosing environment of ncol
is where it was _defined_ not where it is _called_ (apologies if I am
messing up the computer science terminology here).
This suggests to me that codetools is right. But a more extended example
would be useful. Perhaps there is something special with setOldClass()
which I am no aware of.
Also, Bioconductor has 100s of packages with S4 where codetools works well.
Kasper
[[alternative HTML version deleted]]
More information about the R-devel
mailing list