R/vectorize.R

Defines functions opt.vect

# the way I want to vectorize is a bit different from the standard 
# Vectorize function

opt.vect = function(FUN, ...) {
  Vectorize(FUN, vectorize.args=c("x"))
  dots = list(...)
  # print(dots)
  function(x) {
    if(is.null(dim(x))) {
     # if(length(as.list(formals(FUN)))>1) {
      #  FUN(x, dots)
      # } else {
         FUN(x)
      # }
    } else {
     # if(length(as.list(formals(FUN)))>1) {
      #   apply(x, 1, FUN, dots)
      # } else {
          apply(x, 1, FUN)
      #}
    }
  }
}

Try the optim.functions package in your browser

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

optim.functions documentation built on May 2, 2019, 9:57 a.m.