1

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.

A. Suliman
  • 12,923
  • 5
  • 24
  • 37

1 Answers1

0

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.

A. Suliman
  • 12,923
  • 5
  • 24
  • 37
  • It's a very bad idea to access an object specifying the memory location. Why you want to do that, since the environment is accessible in many other ways? – nicola Mar 25 '19 at 10:57
  • @nicola at that time I only knew how to access environments using environment's name and `ls(envir = attr(JMFit1$model_info$coxph_components$TermsU, ".Environment"))` failed at the first time, hence, I thought maybe I can access the environment using the ref id. Given it's a bad idea I would like to know about it or if you can point me to another sources. – A. Suliman Mar 25 '19 at 11:10