Error; object of type 'closure' is not subsettable

Hi Guys

I have quick question if you have a spare minute.

I am using the function below named 'functionx'

function (data = data1, n0 = 1000, m = 5000)
xnamesls = makesubsets(data, maxsize = dim(data)[2])
M = length(xnamesls)
thetamls = mapply("factort", xnames = xnamesls, MoreArgs = list(data = data,
nu = nu, trainpct = trainpct, priorczz = priorczz, diag = diag,
n0 = n0, m = m), SIMPLIFY = FALSE)
outls = vector("list", M)
modnames = rep(0, M)
for (i in 1:M) {
logmargi = attr(thetamlsi, "logmarg")
outls[[i]] = list(xnames = xnamesls[[i]], logmarg = logmargi)
names(outls) = modnames
scandf = makedffrommscan(scanls = outls, data = data)
scandford = scandf[order(scandf$logmarg, decreasing = T),
scanls = list(scandf = scandf, scandford = scandford, scanls = outls)
return(scanls = scanls)

The object of interest is the highlighted 'scandf'.

However when I try to extract this function of interest using the below command:

scandf = functionx$scandf

I get the error ;

object of type 'closure' is not subsettable.

I see online this means I am treating the function like a data frame, but I am unsure how to correct this issue.

Do you guys know how to access an item within a function using $, or is there a better way for me to do this?

Thanks in advance


Is you want scandf then make the function return that object instead of scanls and then you can do

scandf <- functionx()

Any function in namespace—df and data, among many more—can do this, but not always. It's best to avoid using these "reserved words" or to mimic them with capitalization or adding a suffix, such as df_.

This topic was automatically closed 21 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.