An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130224/f219160b/attachment.pl>
Error in J[time] : invalid subscript type 'closure'
3 messages · Jannetta Steyn, Berend Hasselman, MacQueen, Don
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
3 days later
In my experience, error messages that include the word "closure" almost
always mean that I have tried to do something with a function that isn't
supposed to be done with a function (undoubtedly not a technically correct
statement, but it works for me).
I think that applies here, since time is a function in the R stats package:
> find('time')
[1] "package:stats"
So, consistent with Berend's suggestion, the expression
s_fun(parms, time)
is passing the time() function to the expression
J[time]
and it makes no sense to use a function as an index to a numeric vector. I
also believe that is why the error message said, "invalid subscript type".
-Don
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
On 2/24/13 2:24 AM, "Berend Hasselman" <bhh at xs4all.nl> wrote:
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
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.