I'm having a bit of trouble understanding how to use calls in R. I want to take an object created by a function and use it as an argument to another function, modifying some of the arguments to the original function along the way. I've looked at [Hadley Wickham's page on expressions,](http://adv-r.had.co.nz/Expressions.html) but it doesn't quite seem to tell me how to do what I want to do.

Here is a partially-working example of the sort of thing that I want to do. First, fake data:

```
library(MASS)
N <- 1000
p <- 10
A <- matrix(rnorm(p^2), p)
X <- mvrnorm(N, rep(0, p), t(A) %*% A)
B <- rnorm(p)
y <- X %*% B + rnorm(N)

```

Next, a function to do ridge regression. It is a function of `X`, `y`, and the ridge penalty `L`. It returns the coefs and the call:

```
pols <- function(X, y, L){
  cl <- match.call()
  beta <- solve(t(X) %*% X + diag(rep(L, p))) %*% t(X) %*% y
  return(list(beta = beta, cl = cl))
}

1> pols(X, y, 1)
$beta
             [,1]
 [1,] -0.02622669
 [2,] -1.96523722
 [3,]  0.36375563
 [4,] -1.14192468
 [5,] -0.14436051
 [6,] -0.29700918
 [7,] -0.81543748
 [8,] -0.17699934
 [9,] -0.01342649
[10,]  0.58862577

$cl
pols(X = X, y = y, L = 1)

```

Now, how do I use the call to drive the following function? It takes a `pols` object and a vector of different values of `L` and uses them to re-call `pols`

```
Lvec <- 1:10    
tryLs <- function(pols, Lvec){
      for (i in Lvec){
        1.  Extract the args from the call in pols
        2.  Modify the argument `L` based on Lvec
        3.  Run `pols` with old arguments, but `L` modified according to `i`
      }
    }

```

How do I make this last function work?

To clarify, the workflow I'm envisioning is something like:

```
obj <- pols(X, y, 0)
Lvec <- 1:10
output <- tryLs(obj, Lvec)

```