Q:

optimx function in R

I am trying to use the optimx function in R, but keep getting the error message: 
  Error in optimx.check(par, optcfg$ufn, optcfg$ugr, optcfg$uhess, lower,  : 
  Cannot evaluate function at initial parameters
I have looked at another stackoverflow question  R- Optimx for exponential function with 2 parameters - cannot evaluate function at initial parameter values
but that solution has not worked for me.  
Here is my test data:
t <- seq(from=1,to=60,by=1)
len <- 100*(1-exp(-0.2*(t-0)))

t.data<-data.frame(t,len)

starting values for par in the optimx function
p <- as.vector(c(30,110,0.3,1.0)) 

ages for the function below
Age1 <- 1    #### a young age
Age2 <- 50   #### an old age

function to be minimized
schnute_richards <- function(p,data) # which are Len1,Len2,K,R
           {
            zero <- p[1]^p[4]                         #  Len1^R
            one <- p[2]^p[4]-p[1]^p[4]                # (Len2^R-Len1^R)
            two <- 1-exp(-p[3]*(data$t-Age1))     # (1-EXP(-K*(ObsAge-Age1)))
            three <- 1-exp(-p[3]*(Age2-Age1))         # (1-EXP(-K*(Age2-Age1)))
            pred <- (zero + one*(two/three))^(1/p[4]) # final equation
            sum((data$len-pred)^2)
            } 

optimx code
temp <-optimx(p,function (x) schnute_richards(x[1],x[2]))

I tried other versions of this code, but I get the same error message.  This code was used in the other stackoverflow message I referred earlier that was the solution.  
Thanks for any help. 

A:

Study help(optimx).
library(optimx)
temp <- optimx(p, schnute_richards, data = t.data)
#                  p1       p2        p3        p4        value fevals gevals niter convcode  kkt1 kkt2 xtimes
#Nelder-Mead 18.12639 99.99589 0.1999604 1.0005907 7.282821e-05    475     NA    NA        0 FALSE TRUE   0.03
#BFGS        18.12844 99.99493 0.2000565 0.9993415 6.034452e-05     82     20    NA        0 FALSE TRUE   0.01

