Riccardo
Riccardo

Reputation: 2007

R pass further argument to function

I'm writing a function like this:

myFunction <- function(x, y, z) {
    value <- lapply(x, function(x) {
                           value <- otherFunction(y, z, k, j)
                           return(value)
                       }
             )
}

Is there a way to "use" the k and j parameters of the function called within lapply, without explicitly writing them into the argument part of myFunction?

EDIT

This could be a running example:

myl <- list(A=c(1:20), B=c(10:30), C=c(20:40))

myFunction <- function(l, ...){
    value <- lapply(l, function(x, ...){
        log(x, base=exp(100))
    })
    return(value)
}

myFunction(l=myl)

The thing I would know is if it is possible to change the base parameter of the log function even if it is not explicitly declared into the function argument myFunction <- function(l, ...).

All the best

Upvotes: 0

Views: 2094

Answers (1)

David Arenburg
David Arenburg

Reputation: 92282

I'm not entirely sure I understand you, but I think this is what you want

myFunction <- function(l, ...){
  value <- lapply(l, function(x){
    log(x, ...)
  })
  return(value)
}

Then you can run it (for example)

myFunction(l = myl, base = exp(100))

Upvotes: 5

Related Questions