Access an environment using reference id 0x00000000

北战南征 提交于 2019-12-11 07:56:53

问题


I have a model object which shows larger size in hard disk than in R. After some searching, I managed to get the problem cause as shown below

format(object.size(JMFit1$model_info$coxph_components$TermsU), units='Mb')
[1] "0 Mb"
pryr::object_size(JMFit1$model_info$coxph_components$TermsU)
28.5 MB

However JMFit1$model_info$coxph_components$TermsU returns

>JMFit1$model_info$coxph_components$TermsU
...
attr(,".Environment")
<environment: 0x0000000025035540>
...

So, is there any way to access this environment using the reference id i.e. "0x0000000025035540" and then apply ls for example to explore it.

Here are the questions I try Q1 and Q2, but without success. Also, I have tried ls(envir=attr(lm.fit.full$terms, ".Environment")) from this blog but it through the following error

Error in ls(envir = attr(JMFit1$model_info$coxph_components$TermsU, ".Environment")) : invalid 'envir' argument

The full model:

library(JMbayes)
MixedModelFit1 <- mvglmer(list(log(serBilir) ~ year + (year | id)), data = pbc2, families = list(gaussian))
pbc2.id$Time <- pbc2.id$years
pbc2.id$event <- as.numeric(pbc2.id$status != "alive")
CoxFit <- coxph(Surv(Time, event) ~ drug + age, data = pbc2.id, model = TRUE)
JMFit1 <- mvJointModelBayes(MixedModelFit1, CoxFit, timeVar = "year")

Many thanks in advance for any suggestion or help.


回答1:


Here is a way, it does not use the ref id but it use the blog method correctly:

ls(envir=attr(JMFit1$model_info$coxph_components$TermsU$`log(serBilir)_value`, ".Environment"))

To get an object from that env we can do:

env <- attr(JMFit1$model_info$coxph_components$TermsU$`log(serBilir)_value`, ".Environment")
#To get Data for example
d <- get("Data",envir=env)
> typeof(d)
[1] "list"
> format(object.size(d),units='Mb')
[1] "2.8 Mb"

But, I'm still curious if there is a way using the ref id, especially @Spacedman said here that Trying to get R objects by their memory location is not going to work., but I hope maybe there is an update since 2014.



来源:https://stackoverflow.com/questions/53423708/access-an-environment-using-reference-id-0x00000000

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!