How to add more arguments of a function in do.call?
Asked Answered
E

1

6

My question is how I might be able to add more arguments to the do.call function.

For example, I want to draw faceted grid plots with grid.arrange, how can I add more arguments such as ncol=3 and main="main title" to the command do.call(grid.arrange,plots)?

Elgin answered 21/9, 2014 at 18:44 Comment(2)
do.call(fun, c(args, list(otherargs)))Magnus
be sure to name your arguments.Psychogenic
M
9

consider this list of plots,

library(ggplot2)
library(gridExtra)
pl = replicate(5, qplot(1,1), simplify = FALSE)

you can combine it with a list of options to be passed to do.call,

do.call(grid.arrange, c(pl, list(ncol=5, main="title")))
Magnus answered 21/9, 2014 at 18:54 Comment(1)
threw me an error: > do.call(grid.arrange, c(pl, list(ncol=5, main="title"))) Error in gList(list(grobs = list(list(x = 0.5, y = 0.5, width = 1, height = 1, : only 'grobs' allowed in "gList" In addition: Warning message: In grob$wrapvp <- vp : Coercing LHS to a listDiscomposure

© 2022 - 2024 — McMap. All rights reserved.