Jannetta Steyn
2013-Feb-24 09:59 UTC
[R] Error in J[time] : invalid subscript type 'closure'
Hi All I have Googled the message Error in J[time] : invalid subscript type 'closure', but can't quite make sense from the results that I get. What does it mean? I'm trying to access an element in an array. Here is a short bit of code that produces the error: s_fun <- function(parms,time) { with(as.list(c(parms)),{ print(J[time]) }) } times = seq(from=0, to=100, by = 0.1); v<-14 J<-c(rep(c(rep(0,10),rep(v,10)),5)) parms=c(J) out <- s_fun(parms, time) Thanks for your help Regards Jannetta -- ==================================Web site: http://www.jannetta.com Email: jannetta@henning.org ================================== [[alternative HTML version deleted]]
Berend Hasselman
2013-Feb-24 10:24 UTC
[R] Error in J[time] : invalid subscript type 'closure'
On 24-02-2013, at 10:59, Jannetta Steyn <jannetta at henning.org> wrote:> Hi All > > I have Googled the message Error in J[time] : invalid subscript type > 'closure', but can't quite make sense from the results that I get. What > does it mean? > > I'm trying to access an element in an array. Here is a short bit of code > that produces the error: > > s_fun <- function(parms,time) { > > with(as.list(c(parms)),{ > print(J[time]) > }) > } > times = seq(from=0, to=100, by = 0.1); > v<-14 > J<-c(rep(c(rep(0,10),rep(v,10)),5)) > parms=c(J) > out <- s_fun(parms, time) >Look at your code carefully. The error is staring you in the face. The second argument in the call of s_fun is "time" which is nit evaluated immediately. You probably meant "times". Berend