I have a function that I would like to call with a certain parameter as one of the dot-dot-dot paramets (col
) unfortunately this function already has three named variables starting with col
(colNonSig
, colSig
, and colLine
) and so preferentially matches these:
As the documentation above mentions, I would like to pass through col
to the underlying call to plot
.
CodePudding user response:
The body of the function plotMA
can be found here and in its second last line includes a call to base R plot
that looks like this:
plot(object$mean, pmax(ylim[1], pmin(ylim[2], py)),
log = log, pch = ifelse(py < ylim[1], 6, ifelse(py > ylim[2], 2, 16)),
cex = cex, col = ifelse(object$sig, colSig, colNonSig), xlab = xlab,
ylab = ylab, ylim = ylim, ...)
You can see that internally, plotMA
already uses the col
parameter, by taking the colNonSig
and colSig
variables and using them to determine what color the points will be based on their significance level. This is why you get the error about matching multiple arguments. It is not that you are partially matching arguments with plotMA
, but that you are passing two col
arguments to base R's plot
inside the plotMA
function.
There is no direct way round this that will allow you to pass col
directly to the function, but since you want to pass a vector of colors instead, you should get the same result by passing the vector of colors you wanted to pass to both colSig
and colNonSig
, since this will result in a copy of that vector being passed to col
internally.
Your other option is to create your own copy of the function which just removes the col = ifelse(object$sig, colSig, colNonSig),
in the above code, but that seems a bit pointless when the work-around is so easy.