metrumresearchgroup / mrgsolve

Simulate from ODE-based population PK/PD and QSP models in R
https://mrgsolve.org
129 stars 36 forks source link

Export or print updated model code #1177

Closed RichardHooijmaijers closed 1 month ago

RichardHooijmaijers commented 6 months ago

I have a case where I want to update a model with for instance new parameter values. I also want to print or save this updated model code, but struggling to do so. For instance:

library(mrgsolve)
# Load a model
mod  <- house()
# Update a parameter 
mod2 <- param(mod,CL=2)

# This will all print the original model code
mod2$code 
mrgsolve:::code(mod2)  
see(mod2, raw=TRUE)
# This line does not work, also the example in the help file fails
# mrgsolve:::render(mod2)

Is there a way to print the entire model code where the new parameter value (CL=2) is included? Thanks!

jimm3134 commented 4 months ago

workaround - use mrgsolve:::code(mod2) to print to the console, then select that code with your mouse and copy it to a document for printing.

RichardHooijmaijers commented 4 months ago

Hi @jimm3134 thanks for your reply. I used mrgsolve:::code(mod2) in my example. And although this prints the model, it is the original model. I would like to know if there is a way which shows the updated model (e.g. where CL is set to 2)

kylebaron commented 4 months ago

Hi @RichardHooijmaijers - I'm sorry for the delay responding to your question. There isn't currently a way to write the updated object back to the model specification format. The best you can do is save the object to, say, .rds file and then read it back in when needed. mrgsolve:::code() (or mod@code) always goes back to the original model code. I am working on a feature to write the different model components out in .json format to be read back in; that would also preserve updated components of the model. But it would give you a version of the model code that is transportable and readable.

Kyle

RichardHooijmaijers commented 4 months ago

Hi @kylebaron thanks for clarifying! I really like the idea of using json format including options for updated components. Will keep an eye out for this.

kylebaron commented 1 month ago

@RichardHooijmaijers this is now released to CRAN: https://cran.r-project.org/package=mrgsolve

I'm expecting we'll need some refinement of some sort; so please open an issue if you see anything that could be improved.