Unable to save or knit Rmd "object of type closure is not subsettable"

I always have this error message appear whenever I try to save or knit my Rmd file, ever since I started using R. I know it means I am using an object as a function when it is not, but I don't know how to fix it in the context of my code?

Avoid naming your own objects after builtins such as

  • data
  • df
  • D

because then you have always be aware of when they go in and out of namespace scope. One might think that data is safely assigned, but it’s easy to be wrong. Using alternatives makes it difficult to be wrong.

For data frames I prefer d for data. If it’s all numeric, I use m. Makes scripting easier, too.

Thanks for your answer! I changed the name of my table to 'fish' and the code runs the same, but now when I try to knit I get this error answer:

Remember when your data wasn't in namespace data()was taken? Same thing is happening here, except there is no fish swimming in the namespace by default from a loaded library.

The chunk showing fish contradicts this view, but I often see ghost chunks left over from interacting with the document before knitting. What I do to keep track is to bring anything I will be working with into namespace in the setup chunk, which gives the following chunks a better chance to see them.

Thanks again. I'm sorry if my questions sound stupid, I am a beginner when it comes to coding. I made sure to replace the term data with fish in all chunks and renamed my data table fish. The table also appears named that way in the environment. So, to solve this, do I need to write a setup chunk defining fish as a dataset? Something like fish<-dataset? I am a bit confused as to how I would go about this.

Im suggest you put in the first chunk all the data set and libraries. Take in your mind that @technocrat said about the data objects
Im show a image like example:


Im make this for all Rmd file, put in the first chunk the libraries and load the data. Maybe it can be a good practice for you.

Thanks! I finally figured it out by adding read_excel and using tinytex.

1 Like

As a general comment, I'd say "object of type 'closure' is not subsettable" is the least informative error message in the whole R universe.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.