Quantcast

Object of type 'closure' not subsettable

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Object of type 'closure' not subsettable

Muhammad Rahiz
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

# Input sequence in loop
for (i in 1:3){
list <- list.files("~/ukcp09/txt/x.djf", seq[[i]])
file <- lapply(list, read.table)

# Calculations
mean <- (Reduce("+", file))/c
d2[[i]] <- file[[i]] - mean

Apparently, the following command is the source of the error.

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

It works OK when I typed into the terminal the following after running
the script.

 > for (j in 1:3) print (file[[j]]-mean)


Thanks.

Muhammad

--
Muhammad Rahiz  |  Doctoral Student in Regional Climate Modeling
Climate Research Laboratory, School of Geography & the Environment
Oxford University Centre for the Environment
South Parks Road, Oxford, OX1 3QY, United Kingdom
Tel: +44 (0)1865-285194 Mobile: +44 (0)7854-625974
Email: [hidden email]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Object of type 'closure' not subsettable

Barry Rowlingson
On Sun, Dec 20, 2009 at 7:40 PM, Muhammad Rahiz
<[hidden email]> 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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Object of type 'closure' not subsettable

David Winsemius
In reply to this post by Muhammad Rahiz

On Dec 20, 2009, at 2:40 PM, Muhammad Rahiz 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
>
> # Input sequence in loop
> for (i in 1:3){
> list <- list.files("~/ukcp09/txt/x.djf", seq[[i]])
> file <- lapply(list, read.table)
>
> # Calculations
> mean <- (Reduce("+", file))/c
> d2[[i]] <- file[[i]] - mean
>
> Apparently, the following command is the source of the error.
>
> d2[[i]] <- file[[i]] - mean
>
> It works OK when I typed into the terminal the following after  
> running the script.
>
> > for (j in 1:3) print (file[[j]]-mean)

Generally R is able to keep straight what is a vector and what is a  
function but you are using quite a few names for vectors and lists  
which should be reserved (at least in your head) for functions. Here  
is a list of function names to avoid as object names:

c
file
list
seq
mean

Why not try being so ambiguous? ObF: Would you call your dog "dog"?


--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Object of type 'closure' not subsettable

Muhammad Rahiz
In reply to this post by Barry Rowlingson
Thanks Barry for the clarification.

With regards to the following;

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

renamed to

d2[[i]] <- f[[i]] - m

The object f contains the following so clearly f is subsettable

[[1]]
  V1
1 10
2 10
3 10

[[2]]
  V1
1 11
2 11
3 11

[[3]]
  V1
1 12
2 12
3 12

My plan is to subtract m from each subset of f and to store the output
as each individual subsets. So,

output1 <- f[[1]] - m
output2 <- f[[2]] - m
output3 <- f[[3]] - m

If I run the following to achieve the desired result, there is an error
as written in the subject heading.

d2[[i]] <- f[[i]] - m

If I run the following, the error is gone but I'm not getting the output for each individual file I require

d2 <- f[[i]] - m

The issue is, how do I make d2 subsettable?


Thanks.

Muhammad


Muhammad Rahiz  |  Doctoral Student in Regional Climate Modeling
Climate Research Laboratory, School of Geography & the Environment
Oxford University Centre for the Environment
South Parks Road, Oxford, OX1 3QY, United Kingdom
Tel: +44 (0)1865-285194 Mobile: +44 (0)7854-625974
Email: [hidden email]






Barry Rowlingson wrote:

> On Sun, Dec 20, 2009 at 7:40 PM, Muhammad Rahiz
> <[hidden email]> 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
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Object of type 'closure' not subsettable

Barry Rowlingson
On Mon, Dec 21, 2009 at 1:43 PM, Muhammad Rahiz
<[hidden email]> wrote:

> Thanks Barry for the clarification.
>
> With regards to the following;
>
> d2[[i]] <- file[[i]] - mean
>
> renamed to
>
> d2[[i]] <- f[[i]] - m
>
> The object f contains the following so clearly f is subsettable
>
> [[1]]
>  V1
> 1 10
> 2 10
> 3 10
>
> [[2]]
>  V1
> 1 11
> 2 11
> 3 11
>
> [[3]]
>  V1
> 1 12
> 2 12
> 3 12
>
> My plan is to subtract m from each subset of f and to store the output as
> each individual subsets. So,
>
> output1 <- f[[1]] - m
> output2 <- f[[2]] - m
> output3 <- f[[3]] - m
>
> If I run the following to achieve the desired result, there is an error as
> written in the subject heading.
>
> d2[[i]] <- f[[i]] - m
>
> If I run the following, the error is gone but I'm not getting the output for
> each individual file I require
>
> d2 <- f[[i]] - m
>
> The issue is, how do I make d2 subsettable?
>
>

 Well you haven't shown us this time how you initialised d2. Create it
as an empty list:

 d2 <- list()

and then you can do:

 > d2[[1]]=c(1,2,3)
 > d2[[2]]=c(4,5,6)
 > d2
[[1]]
[1] 1 2 3

[[2]]
[1] 4 5 6

 As I said, read one of the basic R documents linked on the
documentation section of the R web site, and play with lists and
vectors for a while.

Barry

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Object of type 'closure' not subsettable

PIKAL Petr
In reply to this post by Muhammad Rahiz
Hi

You were instucted to

> > 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...

which you clearly did not do.

[hidden email] napsal dne 21.12.2009 14:43:44:

> Thanks Barry for the clarification.
>
> With regards to the following;
>
> d2[[i]] <- file[[i]] - mean
>
> renamed to
>
> d2[[i]] <- f[[i]] - m

What is d2? What does

str(d2)

tell about the object.

for everybody except you the error message is

d2[[i]] <- f[[i]] - m
Error: object 'f' not found

So what do you expect? Barry clearly explained that d2 is probably a
function based on what you explained that you did.

d2<-file
d2[[1]]
Error in d2[[1]] : object of type 'closure' is not subsettable

Besides of reading a tiny part of R intro docs especially about objects
and how to manipulate them you could consult also apply family of
functions (lapply, sapply, ...) and also ave which probably do what you
want without twisting R to C programming.

ave(some.data, some.levels, FUN=function(x) x-mean(x))
shall do what you want

Regards
Petr


>
> The object f contains the following so clearly f is subsettable
>
> [[1]]
>   V1
> 1 10
> 2 10
> 3 10
>
> [[2]]
>   V1
> 1 11
> 2 11
> 3 11
>
> [[3]]
>   V1
> 1 12
> 2 12
> 3 12
>
> My plan is to subtract m from each subset of f and to store the output
> as each individual subsets. So,
>
> output1 <- f[[1]] - m
> output2 <- f[[2]] - m
> output3 <- f[[3]] - m
>
> If I run the following to achieve the desired result, there is an error
> as written in the subject heading.
>
> d2[[i]] <- f[[i]] - m
>
> If I run the following, the error is gone but I'm not getting the output
for

> each individual file I require
>
> d2 <- f[[i]] - m
>
> The issue is, how do I make d2 subsettable?
>
>
> Thanks.
>
> Muhammad
>
>
> Muhammad Rahiz  |  Doctoral Student in Regional Climate Modeling  
> Climate Research Laboratory, School of Geography & the Environment
> Oxford University Centre for the Environment
> South Parks Road, Oxford, OX1 3QY, United Kingdom
> Tel: +44 (0)1865-285194    Mobile: +44 (0)7854-625974
> Email: [hidden email]
>
>
>
>
>
>
> Barry Rowlingson wrote:
> > On Sun, Dec 20, 2009 at 7:40 PM, Muhammad Rahiz
> > <[hidden email]> 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
> >
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Object of type 'closure' not subsettable - OK

Muhammad Rahiz
Thanks Petr, Barry & David for your useful comments.

Given

d2[[i]] <- f[[i]] - m

The problem lies in how I define the object, d2[[i]], which I managed to
resolve by

 > d2 <- list()

--
Muhammad Rahiz  |  Doctoral Student in Regional Climate Modeling
Climate Research Laboratory, School of Geography & the Environment
Oxford University Centre for the Environment
South Parks Road, Oxford, OX1 3QY, United Kingdom
Tel: +44 (0)1865-285194 Mobile: +44 (0)7854-625974
Email: [hidden email]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Object of type 'closure' not subsettable in GROFIT

trubilar
In reply to this post by Muhammad Rahiz
Hello Everyone, I am quite new in R software.
I am doing a grofit to study growth.
I have a matrix of time with 10 weeks and 26 individuals ie 10 columns x 26 rows
and I have a data.frame with 3 columns: 1 for Individual Id (which repeats it self, since I have 10 values for each individual correponding to each week) the size of the individual (1 or 2) and the Length value.

I run the grofit and get the following error
Data error [-1:-3]: object type "closure" not subsettable

I have no idea what it means or if I am doing something wrong!
Could anyone help me?
Thanks


Tamara Rubilar
Lab. Bentos
Centro Nacional Patagonico
Puerto Madryn
Argentina
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Object of type 'closure' not subsettable in GROFIT

Duncan Murdoch-2
On 19/05/2010 10:34 AM, trubilar wrote:

> Hello Everyone, I am quite new in R software.
> I am doing a grofit to study growth.
> I have a matrix of time with 10 weeks and 26 individuals ie 10 columns x 26
> rows
> and I have a data.frame with 3 columns: 1 for Individual Id (which repeats
> it self, since I have 10 values for each individual correponding to each
> week) the size of the individual (1 or 2) and the Length value.
>
> I run the grofit and get the following error
> Data error [-1:-3]: object type "closure" not subsettable
>
> I have no idea what it means or if I am doing something wrong!
>  

You are trying to index a function.  Possibly you're using brackets
instead of parentheses when calling it?  E.g.

 > mean(1:2)   # correct
[1] 1.5

 > mean[1:2]   # incorrect
Error in mean[1:2] : object of type 'closure' is not subsettable
   
If that doesn't help enough, please simplify your problem to a
self-contained one of a few lines and post it here.  Someone will work
it out.

Duncan Murdoch

> Could anyone help me?
> Thanks
>
>
> Tamara Rubilar
> Lab. Bentos
> Centro Nacional Patagonico
> Puerto Madryn
> Argentina
>

______________________________________________
[hidden email] 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.
Loading...