Skip to content

Commit

Permalink
ordiplot(<rda>) passes arguments to plot.cca: fixes part of #685
Browse files Browse the repository at this point in the history
Still does not handle arguments optimize and arrows when passed
from ordiplot to plot.cca.
  • Loading branch information
jarioksa committed Aug 28, 2024
1 parent e477097 commit cafdc03
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion R/plot.cca.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,5 @@
if (!("CA" %in% names(x)))
stop(gettextf("%s is not a vegan rda object",
sQuote(deparse(substitute(x)))))
NextMethod("plot", x, ...)
plot.cca(x, ...)
}

3 comments on commit cafdc03

@gavinsimpson
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original issue was that you were calling

NextMethod("plot", x, ...)

and none of those arguments are actually necessary for NextMethod() to work.

If I fixInNamespace("plot.rda", "vegan") and edit the NextMethod call to be an empty function call

NextMethod()

(Instead of your fix in this commit) I get the expected behaviour (no error from match.call()) and as an added bonus, optimize = TRUE appears to work.

@jarioksa
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh! Fine if it works, but I do not (yet) understand how it works. Please go on!

@gavinsimpson
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider the call:

ordiplot(ord, scaling = "sites", optimize = TRUE)

where ord is an RDA object

I think the issue is that NextMethod() (empty) arranges to call plot.cca() with the original arguments, so we get

plot.cca(ord, scaling = "sites", optimize = TRUE)

You'd get the same behaviour if you spell out the generic and object arguments explicitly

NextMethod("plot", x)

would also get you

plot.cca(ord, scaling = "sites", optimize = TRUE)

But when you do NextMethod("plot", x, ...), the ... is documented in ?NextMethod to be extra arguments to be used in the call, on top of the arguments in the original call. So, with your original code

NextMethod("plot", x, ...)

everything that was part of the ... in the original call to ordiplot() will get included twice, once as a result of the normal way NextMethod() works and a second time because you passed ... on as extra arguments. The resulting call will be

plot.cca(ord, scaling = "sites", optimize = TRUE, scaling = "sites", optimize = TRUE)

and hence the error.

NextMethod is like dark magic and I don't really understand how it does what it does, but I'm pretty sure NextMethod() or NextMethod("plot", x) will fix the issue.

Please sign in to comment.