Dealing with Error: Object of type ‘closure’ is not subsettable

As a general rule, this error indicates you have attempted to treat a variable which is a function as if it were an index-able data type such as data frame. This error frequently occurs when you are building web applications using the shiny framework using the reactive () function.

For those not familiar with functional programming, a closure refers to a function (created at run-time) that can be passed around like a variable. This programming approach can significantly simplify code development.

For R shiny development, this error frequently occurs after you have created objects such as dataframes, lists, and vectors using the reactive() function. It is tempting to attempt to treat the object after this point as if it were an ordinary index-able data type, using brackets to reference specific elements of the data object. Which will result in the error message in question: “Object of type ‘closure’ is not subsettable“.

For shiny development, remember you need to use brackets when referencing an object created using the reactive () function. Something along the lines of:




If you get this error during other types of R development, double check your variable names to make sure you’re not mixing variable names. Along the same lines, avoid naming variables the same (or similar) names as the functions contained within the base R library to reduce the risk of creating an “Object of type ‘closure’ is not subsettable” error via a typo.

Error: object of type ‘closure’ is not subsettable