[R] Object of type 'closure' not subsettable

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Sun Dec 20 21:25:15 CET 2009


On Sun, Dec 20, 2009 at 7:40 PM, Muhammad Rahiz
<muhammad.rahiz at ouce.ox.ac.uk> wrote:
> Hi all,
>
> How can I overcome the error "object of type 'closure' not subsettable"
>
> I ran the following script
> seq <- paste(seq(1914, 1916, by=1), "*.y", sep=".") # make sequence
> c <- 3 # total number of files
> d2 <- file # creates dummy file

 No it doesn't. It copies the object called 'file' into an object
called 'd2'. What's the object called 'file'? If you've not created
one already, its the 'file' function that R uses to read stuff from
files. So when you do:


> d2[[i]] <- file[[i]] - mean

 you are trying to subset from d2 (and from 'file'). If I do this:

 > file[[2]]

 I get your error message:

Error in file[[2]] : object of type 'closure' is not subsettable

 So clearly you aren't doing what you think you're doing.

 Some hints:

1. Read a good introduction to R. You are making a number of
fundamental mistakes here.

2. Run each line separately and check what value you get back by printing it.

3. Don't give your objects the same name as R functions (you're using
'seq', 'file', and 'mean'). Although this may work, it will confuse
people later...

Barry




More information about the R-help mailing list