nlmixrdevelopment / nlmixr

nlmixr: an R package for population PKPD modeling
https://nlmixrdevelopment.github.io/nlmixr/
GNU General Public License v2.0
114 stars 45 forks source link

Odd function not found when running multiple R sessions in Windows #565

Open billdenney opened 2 years ago

billdenney commented 2 years ago

While trying to reproduce an error in a new R session in Windows, I got the following error:

function 'rx_6da85640ffa7bf86453c001841615f7d_x64_calc_lhs' not provided by package 'rx_6da85640ffa7bf86453c001841615f7d_x64'

What I did was:

The specific code I was running is:

library(nlmixr)

nlmixr_onecmt <- function() {
  ini({
    tfsc <- log(0.5)
    tka <- log(0.001)
    tcl <- log(0.03)
    tv <- log(1.5)
    eta_cl~0.05
    eta_v~0.05
    prop_err <- 0.01
    add_err <- 1
  })
  model({
    fsc <- exp(tfsc)
    ka <- exp(tka)
    cl <- exp(tcl + eta_cl)
    v <- exp(tv + eta_v)
    ke <- cl/v
    d/dt(SC) = -ka * SC
    d/dt(CENTRAL) = ka * SC - ke * CENTRAL
    f(SC) <- fsc
    cp = CENTRAL/v*1e3 # 1e3 is for unit conversion
    cp ~ prop(prop_err) + add(add_err)
  })
}

data <- readr::read_csv("c:/tmp/data.csv")

nlmixr(
  object=nlmixr_onecmt,
  data=data,
  #est="saem",
  est="focei",
  control=list(print=1, outerOpt="bobyqa"), 
  table=list(cwres=TRUE, npde=TRUE)
)

(I'm about to try to anonymize the data so that I can provide it in the other issue.)

mattfidler commented 2 years ago

At the beginning of the session, clean the cached models. That is:

rxClean()

This assumes you setup the cache (which ti think you had to do to use drake)

billdenney commented 2 years ago

That fixed it. Thanks! Any way that the user can be told to do that if this issue occurs?

mattfidler commented 2 years ago

All things are possible, It is difficult to test, though, so difficult to catch and see what the problem could be. If I could catch it, I could also simply clean it and then recompile the model from the beginning.

It has become less common now that RxODE removes the cache for a new version of RxODE or nlmixr

billdenney commented 2 years ago

Looking around a bit, I found that I could do ls("package:base") to get a list of all functions in a package. That seems like it's moving toward the ability to detect if the function exists. But, you would still need to be able to know the name of the function to check it against that list.