FormalsToDf: Handle vector arguments to functions in a collated fashion.

Description Usage Arguments Value Examples

Description

FormalsToDf is called inside a function where some formal arguments may have been supplied as vectors. FormalsToDf constructs a dataframe from the arguments which can then be passed to plyr::mlply (or similar, e.g. mdply) to return a list of results. The assumption is that all vector arguments are collated: 1) NULL arguments are dropped; 2) all arguments of length > 1 all have the same length and are collated.

Usage

1
FormalsToDf(theFunc, envir = parent.frame())

Arguments

meta

Character the metadata field.

package

Character The package to query for metadata.

Value

Dataframe

Examples

1
2
3
4
5
6
7
8
## A stupid example where true vectorization is possible
myF.atomic <- function(x,y,z=NULL) if(is.null(z)) x+y else x+y+z  
myF <- function(x,y,z=NULL) { 
  col <- FormalsToDf(myF) 
  plyr::maply(col, myF.atomic, .expand=FALSE)
  }
myF.atomic(x=11:13,y=1:3)
myF(x=11:13,y=1:3)

mccreigh/rwrfhydro documentation built on Feb. 28, 2021, 1:53 p.m.