[R] Referencing a component of a large object (Error: slot NULL)

William Dunlap wdunlap at tibco.com
Sat Aug 29 05:59:09 CEST 2015


   s <- paste("'chain:",j,"'" ,sep="")

You don't want the single quotes around the string you are constructing.
Try
   s <- paste0("chain:", j)
which will give you, e.g.,
   "chain:1"
instead of
   "'chain:1'"

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Fri, Aug 28, 2015 at 6:08 PM, Andrea Lamont <alamont082 at gmail.com> wrote:

> Hm.
>
> It still doesn't seem to be working and has me completely stumped.
>
> This works:
> mi.control.i at data[['chain:1']]@variables$y.obs.tx at parameters[30,]
>
> But this doesn't:
> > mi.control.i at data[[s]]@variables$y.obs.tx at parameters[30,]
> Error: trying to get slot "variables" from an object of a basic class
> ("NULL") with no slots
> > s
> [1] "'chain:1'"
>
> On Fri, Aug 28, 2015 at 5:52 PM, William Dunlap <wdunlap at tibco.com> wrote:
>
>>
>>   tf <- vector("list", numberofchains)
>>   for (j in 1:numberofchains){
>>       s <- paste("'chain:",j,"'" ,sep="")
>>       tf[[j]] =  mi.control.i at data$s at variables$y.obs.tx at parameters[30,]
>>   }
>>
>>
>> If you want the component whose name is the value of the variable 's'
>> use data[[s]].
>>
>> The syntax 'data$s' means to get the component of 'data' called "s",
>> usually the same as 'data[["s"]]'.
>>
>>
>> Bill Dunlap
>> TIBCO Software
>> wdunlap tibco.com
>>
>> On Fri, Aug 28, 2015 at 12:08 PM, Andrea Lamont <alamont082 at gmail.com>
>> wrote:
>>
>>> I am running a simulation and need to refer to a matrix of parameters
>>> from
>>> a large object. Here is a snippet of the object structure itself:
>>>
>>> Formal class 'mi' [package "mi"] with 3 slots
>>>   ..@ call       : language .local(y = y, n.chains = ..2, max.minutes =
>>> 20000)
>>>   ..@ data       :List of 100
>>>   .. ..$ chain:1  :'data.frame':    10000 obs. of  76 variables:
>>> Formal class 'missing_data.frame' [package "mi"] with 17 slots
>>>   .. .. .. ..@ .Data       : list()
>>>   .. .. .. ..@ variables   :List of 76
>>>   .. .. .. .. ..$ y.obs.tx:Formal class 'binary' [package "mi"] with 27
>>> slots...
>>>
>>> The parameter list I need can be referenced by:
>>>
>>> mi.control.i at data$'chain:1'@variables$y.obs.tx at parameters[30,]
>>>
>>> Since this is a simulation, I would like to grab the parameters from each
>>> chain and join them together in a matrix. I have this:
>>>
>>> tf <- vector("list", numberofchains)for (j in 1:numberofchains){
>>>   s <- paste("'chain:",j,"'" ,sep="")
>>>   tf[[j]] =  mi.control.i at data$s at variables$y.obs.tx at parameters[30,]}
>>>
>>> Within the loop, however, the reference to the object (tf[[j]]) does not
>>> work. I get an error that reads
>>>
>>> Error: trying to get slot "variables" from an object of a basic class
>>> ("NULL") with no slots
>>>
>>>
>>> I am happy to send reproducible code, however, I obtain this object
>>> through
>>> the package 'mi' and is computationally intensive. I'm not sure if it
>>> makes
>>> it easier for folks. Let me know.
>>>
>>> Any ideas?
>>>
>>> --
>>> Andrea Lamont, PhD
>>> Post-Doctoral Fellow
>>> University of South Carolina
>>> Columbia, SC 29208
>>>
>>> *Please consider the environment before printing this email.*
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> 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.
>>>
>>
>>
>
>
> --
> Andrea Lamont, PhD
> Post-Doctoral Fellow
> University of South Carolina
> Columbia, SC 29208
>
> *Please consider the environment before printing this email.*
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list