Question: For example [1,2,3] and i want to add 5 to the 2nd element so that I get [1,7,3]. Would this actually be possible?

Answer: 
One problem is that if `len==1`, then `argms[2:len]` returns a list of length 2; in particular,

```
> identical(argms[2:1], list(NULL, argms[[1]]))
[1] TRUE

```

To fix that you could just drop the first element of the list using `argms[-1]`. 

You also need to make use of your `of` function because as probably you noted `sin(cos)` returns an error rather than a function. Putting this together we get:

```
comp <- function(...) {
  argms <- c(...)
  len <- length(argms)
  if(len==1) { return(of(argms[[1]], id)) }
  else {
    of(argms[[1]], comp(argms[-1]))
  }
}

> comp(sin, cos, tan)(1)
[1] 0.0133878
> compose(sin, cos, tan)(1)
[1] 0.0133878

```
Here is a solution that returns a function which is easy to understand

```r
func <- function(f, ...){
  cl <- match.call()
  if(length(cl) == 2L)
    return(eval(bquote(function(...) .(cl[[2L]]))))

  le <- max(which(sapply(cl, inherits, "name")))
  if(le == length(cl)){
    tmp <- cl[le]
    tmp[[2L]] <- quote(...)
    cl[[length(cl)]] <- tmp

  } else if(le == length(cl) - 1L){
    tmp <- cl[le]
    tmp[[2L]] <- cl[[le + 1L]]
    cl[[le]] <- tmp
    cl[[le + 1L]] <- NULL

  } else
    stop("something is wrong...")

  eval(cl)
}

func(sin, cos, tan) # clear what the function does
#R function (...) 
#R sin(cos(tan(...)))
#R <environment: 0x000000001a189778>
func(sin, cos, tan)(pi/4) # gives correct value
#R [1] 0.5143953

```

One may have to adjust the `sapply(cl, inherits, "name")` line to something more general...