# basic usage of owa itself:
d <- list(bb=1:5, lwd="was d", lty=1, col="gray")
a <- list(bb=3, lwd=5, lty="from a", wachs="A")
owa(d,a) # all changed, wachs added
owa(d, a, "bb", "lwd") # lty is overwritten, bb and lwd are ignored
owa(d, NULL, "bb", "wachs") # NULL is a good default for argument lists
owa(d, c(HH=2, BBB=3) ) # vectors and lists are all converted to lists
owa(d, list(lwd=5, bb=3, lty="1") ) # order of arguments doesn't matter
owa(d, a, c("bb","lwd") ) # unchangable can also be a named vector
owa(d, a, c("bb","lwd"), c("lty","dummy") ) # or several vectors
# Usage example (see applications eg. in funnelPlot, colPoints or mReg)
# Why we want to do this:
testfun <- function(...) {plot(7:9, ...) ; legend("top", "Text hier", ...)}
testfun()
# testfun(type="o") # Error: legend doesn't have the argument 'type'!
# How to solve this:
testfun <- function(data=7:9, legarg=NULL, plotarg=NULL)
{
# defaults for plot and legend:
plot_def <- list(x=0.5*data, col="red", cex=2, lty=2, type="o")
leg_def <- list(x="top", lty=2, legend="Default text here")
# combine defaults and user specified into final argument list
plot_fin <- owa(d=plot_def, a=plotarg, "col", "lty")
leg_fin <- owa(d=leg_def, a=legarg, "lty")
# Execute single functions that each have their own arguments:
do.call( plot, args=plot_fin)
do.call(legend, args=leg_fin)
}
testfun()
testfun(plotarg=list(type="l", col="blue") )
# color is silently ignored, as it is defined as unchangeable
testfun(plotarg=list(type="l"), legarg=list(col="blue", pch=16) )
Run the code above in your browser using DataLab