r - What is the cause of "Error in .C("unlock solver")" Error in deSolve Package? -
i have been using desolve package in mcmc algorithm estimate parameters in ode , wrote functions used in solver in c speed algorithm. sometimes, not error error in .c("unlock solver")
when running ode
function. able compile , link c files using commands
system("r cmd shlib [insert-file-path]") dyn.load("[dll-file-path]")
but when try solve ode using dll file, error thrown. then, when running simple script 1 below, same error. think issue related using compiled code, don't know how , cannot find references on error.
> require(desolve) > initval <- c(y=1) > times <- seq(0, 1, 0.001) > parms <- c(k=1) > model1 <- function(t, y, parms){ + with(as.list(c(y, parms)),{ + dy <- -k*y; + list(c(dy)) + }) + } > out <- ode(y=initval, times=times, parms=parms, func=model1) error in .c("unlock_solver") : "unlock_solver" not resolved current namespace (desolve)
partial solution if restart r , load dll using dyn.load
function, don't compile code, ode
function runs without error. fixes problem, still have no idea why.
edit: real solution thomas petzoldt on r list:
"[the error] occurs, if package desolve loaded after compiled model... solution load desolve before [before loading dll's], ideally @ beginning of script, , @ least before loading/unloading dll/.so"
if doesn't work, below might (old answer):
i have found inelegant solution.
the problem seems "unlock_solver" function within desolve somehow not being accessed correctly. can unload , reload entire desolve.so file, rather restarting r.
to can use like:
require(desolve) # encounter error library.dynam.unload("desolve", libpath=paste(.libpaths()[1], "//desolve", sep="")) library.dynam("desolve", package="desolve", lib.loc=.libpaths()[1])
you'll need replace ".libpaths()[1]" wherever have installed desolve, if isn't in first element of .libpaths variable.
this of sledge hammer, though. i've sent out request r-help list asking if there way either change r looks "unlock_solver", or unload/reload portion of desolve.
Comments
Post a Comment