collectArgs and iterateWithArgs

Overview

This package provides two simply functions to quickly collect all arguments inside one function and then either - iterate on one specific argument or - pass them all to another function.

Example

library(collectArgs)
library(magrittr)

sample_function <- function(x, base, thresh=500, verbose=TRUE) {
  some_object    <- is.na(x) ## an example of an object that we will exclude
  another_object <- 1:10     ## an example of an object that we will exclude

  if (length(x) > 1) {
    return(iterateWithArgs(x, FUNC=sample_function, except=c("some_object", "another_object")))
  }

  ret <- (base ^ x)

  if (verbose)
    cat(base, "^", x, " is ", ifelse(ret > thresh, "", "NOT "), "larger than ", thresh, "\n")

  return(ret)
}

sample_function(5, base=2)
sample_function(5:10, base=2)

Feedback

Feedback is greatly appreciated and all pull requests are considered. Please visit on the Package Homepage on github



Try the collectArgs package in your browser

Any scripts or data that you put into this service are public.

collectArgs documentation built on May 1, 2019, 9:10 p.m.