使用参考ID 0x00000000访问环境 [英] Access an environment using reference id 0x00000000
问题描述
我有一个模型对象,其硬盘中的大小大于R中的大小.经过一些搜索,我设法找到了问题原因,如下所示
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
但是JMFit1$model_info$coxph_components$TermsU
返回
>JMFit1$model_info$coxph_components$TermsU
...
attr(,".Environment")
<environment: 0x0000000025035540>
...
因此,有什么方法可以使用参考ID(例如"0x0000000025035540")访问此环境,然后应用例如ls
进行浏览.
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.
以下是我尝试的问题 Q2 ,但没有成功.另外,我还尝试过从
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
ls(envir = attr(JMFit1 $ model_info $ coxph_components $ TermsU,".Environment"))中的错误: 无效的"envir"参数
Error in ls(envir = attr(JMFit1$model_info$coxph_components$TermsU, ".Environment")) : invalid 'envir' argument
完整模型:
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.
推荐答案
这是一种方法,它不使用ref id,但可以正确使用blog方法:
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"
但是,我仍然很好奇是否有使用ref id的方法,特别是@Spacedman说
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.
这篇关于使用参考ID 0x00000000访问环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!