Make sure you have created a data
variable prior to running the line of code you shared.
In a clean R session try the following,
data
# function (..., list = character(), package = NULL, lib.loc = NULL,
# verbose = getOption("verbose"), envir = .GlobalEnv)
# {
# fileExt <- function(x) {
# db <- grepl("\\.[^.]+\\.(gz|bz2|xz)$", x)
# .. (and more)
data$field
# Error in data$foo : object of type 'closure' is not subsettable
There is a function data()
in the base utils
package, which is loaded by default. An error is raised because right now we are asking R to extract a value from the data
function as though it were a list.
Now let's create a data
object. Once this new variable is created R will automatically distinguish the data
object variable from the data
function variable.
data <- list()
data$field <- "value"
data
# $field
# [1] "value"
Because R, for better or worse, allows this silent distinction detailed variable names are often a safer approach. I hope this helps.