How to list all "..." parameters inside R function
1
0
Entering edit mode
lucap • 0
@lucap-20484
Last seen 15 months ago

Hi there. I am trying to find a way to get a specific list of the additional parameters that are specified within the ... argument of a function inside a library. How do you do that? In particular I would like to know the parameters accepted by the function viewPathway inside the ReactomePA package. By typing formals(viewPathway) I get:

$pathName


$organism
[1] "human"

$readable
[1] TRUE

$foldChange
NULL

$keyType
[1] "ENTREZID"

$layout
[1] "kk"

$...

How do I get a list of those $... ?!?!? It is important because the function creates a plot and it would be useful to know the parameters in order to adjust the look of the plot according to my needs. Thanks a lot guys

Luca

ReactomePA clusterProfiler • 291 views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 2 days ago
United States

The ellipsis argument allows you to pass arbitrary arguments into other functions without having to pre-specify what they are. So something like

fun <- function(x, y, ...){
    plot(x, y, ...)
}

Would allow you to pass ANY argument that plot accepts, without having to ever say what those arguments might be. So you could do

fun(x, y, cex = 2, pch = 16, ylab = "ignore this axis", xaxt = "n")

or anything else that plot might accept. And if you do


fun <- function(x, y, z, ...){
    plot(x, y, ...)
    text(x, y, z, ...)
}

as a stupid example, you could pass any argument(s) that work for either plot or text or both. The only way to know what you can pass to those functions is to look at which functions have an ... argument and then look at all the arguments that those functions can accept.

ADD COMMENT
0
Entering edit mode

Also, this is just a basic R question, not really pertaining to Bioconductor, so in the future you should ask about basic R stuff on r-help@r-project.org or maybe stackoverflow.com

ADD REPLY
0
Entering edit mode

To add to this already detailed answer:

Perhaps the OP was wondering how to interrogate what arguments were actually passed into the function and caught by .... In this case you could convert ... into named list and examine it that way:

fn <- function(x, y, ...) {
  args <- list(...)
  message("These are the extra arguments passed in through `...`:\n")
  message(sprintf("  * `%s` (%s)\n", names(args), sapply(args, class)))
}

Then calling it like so:

fn(x = 1, y = 2, z = 3, df = data.frame(a = 1:10, b = rnorm(20)))

Will give you

These are the extra arguments passed in through `...`:

  * `z` (numeric)
  * `df` (data.frame)
ADD REPLY
0
Entering edit mode

Thanks @James and @Steve. I knew the meaning of the ellipses argument, it just seemed "stupid" to me that there was no way to interrogate a function to explicitly state the arguments that the function accepts in its ellipses. Anyway, from what I understand from your explanation, the only way to do that is to look at the code. I will try. Thanks again

ADD REPLY

Login before adding your answer.

Traffic: 305 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6