<div dir="ltr">There's also <a href="https://github.com/thk686/odeintr">https://github.com/thk686/odeintr</a> (use the devel version, not CRAN -- need to upload a bug fix).<div><br></div><div>THK</div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><a href="http://www.keittlab.org/" target="_blank">http://www.keittlab.org/</a></div></div></div>
<br><div class="gmail_quote">On Wed, Jan 25, 2017 at 11:33 AM, Gibbons, Frank <span dir="ltr"><<a href="mailto:Frank.Gibbons@astrazeneca.com" target="_blank">Frank.Gibbons@astrazeneca.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-US" link="blue" vlink="purple">
<div class="m_9094044376802374474WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Kyle,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">D’oh! You’re absolutely right. Embarrassing. :-}
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">(I’m told that’s the emoticon for ‘sheepish grin’.)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">I did try going the way suggested by deSolve, but find that (for reasons unknown to me), “R CMD SHLIB” compiles the object file but not the DLL (error about not
 having permission).<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">I wasn’t aware of RxODE at all (and only vaguely familiar with mrgsolve), but installed it, read through the tutorial (from the journal CPT-PSP), and within a
 few hours was in business. It won’t be for everyone of course, since it’s specialized for PK/PD modeling, but it enabled me to get a 15x performance improvement in my application (which requires repeated model evaluation to optimize a study design). This is
 huge: over-lunchbreak vs over-night. If the speedup reported by the authors in their tutorial applies to my situation, this improvement factor will improve as the model grows (currently just 2 ODEs).<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">For those with similar goals as mine (PK/PD models), highly recommend it. Much like Rcpp, it enables specification of both the compiled and non-compiled parts
 of the code in a single file. But like SHLIB, it compiles behind the scenes (few seconds), and while I don’t fully understand what’s going on under the hood, it performs as if there’s a minimum of back-and-forth between R and C.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Many thanks to you both<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">-Frank<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Kyle Baron [mailto:<a href="mailto:kyleb@metrumrg.com" target="_blank">kyleb@metrumrg.com</a>]
<br>
<b>Sent:</b> Monday, January 23, 2017 1:35 PM<br>
<b>To:</b> Dirk Eddelbuettel <<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>><br>
<b>Cc:</b> Gibbons, Frank <<a href="mailto:Frank.Gibbons@astrazeneca.com" target="_blank">Frank.Gibbons@astrazeneca.com</a><wbr>>; <a href="mailto:rcpp-devel@lists.r-forge.r-project.org" target="_blank">rcpp-devel@lists.r-forge.r-<wbr>project.org</a><br>
<b>Subject:</b> Re: [Rcpp-devel] Using Rcpp to solve ODEs: LSODE (deSolve) says "Confusion over the length of parms"<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt">Frank - </span><u></u><u></u></p>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt">In the code you provided, it looks like it is "poped.db.compiled.rcpp", not "poped.db.compiled".  <u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt">I found that, after making the change to fix the error that Dirk pointed out, the code appears to work with no error (attached).  I don't know if the results are what you were intending, however.<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt">Also: I would not set up the optimization like this.  When you create the one_comp_oral_ode function with cppFunction and hand that off to deSolve, you are still passing along an R function to get called. 
 Even if the calculations are accomplished with Rcpp, it still an R function.  So every step the solver takes, it will have to call an R function.  I don't think this is what you want. When you write the ode function as suggested by the deSolve package vignette,
 you pass off the name of a C function and the solver calls that C function directly as the system advances.  It will be faster than what you are doing with cppFunction. <u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt">Finally, I'll ask if you have looked at one of the more-modern simulation packages for R that are designed for PK/PD work?<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt">I maintain mrgsolve: </span><a href="https://github.com/metrumresearchgroup/mrgsolve" target="_blank"><span style="font-size:9.5pt">https://github.com/<wbr>metrumresearchgroup/mrgsolve</span></a><span style="font-size:9.5pt"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt">You could also look at RxODE: </span><a href="https://cran.r-project.org/web/packages/RxODE/index.html" target="_blank"><span style="font-size:9.5pt">https://cran.r-project.<wbr>org/web/packages/RxODE/index.<wbr>html</span></a><span style="font-size:9.5pt"><u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt">Hope that helps ...<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt">Kyle<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:9.5pt"><u></u> <u></u></span></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Sun, Jan 22, 2017 at 7:50 PM, Dirk Eddelbuettel <<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<p class="MsoNormal"><br>
Frank,<br>
<br>
That's a pretty long message and a lot of code.  Can you try to distill it<br>
down to a particular (smaller?) issue?<br>
<br>
And FWIW I cannot run. After saving your attachment, and installing PopED, I<br>
get<br>
<br>
R> source("/tmp/myExampleODE.<wbr>compiled.R")<br>
<br>
Attaching package: ‘deSolve’<br>
<br>
The following object is masked from ‘package:graphics’:<br>
<br>
    matplot<br>
<br>
Elapsed time: 10.425 seconds.<br>
Error in poped.db$settings$optsw[2] <- opt_xt :<br>
  object 'poped.db.compiled' not found<br>
R><br>
<br>
I also recommend the rbenchmark and microbenchmark packages over tic() and toc().<br>
<br>
Sorry that I have no quick fix.<br>
<span style="color:#888888"><br>
<span class="m_9094044376802374474hoenzb">Dirk</span><br>
<br>
<span class="m_9094044376802374474hoenzb">--</span><br>
</span><a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a><span class="m_9094044376802374474hoenzb"><span style="color:#888888"> | @eddelbuettel |
</span></span><a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a><span style="color:#888888"><br>
<span class="m_9094044376802374474hoenzb">______________________________<wbr>_________________</span><br>
<span class="m_9094044376802374474hoenzb">Rcpp-devel mailing list</span><br>
</span><a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-<wbr>project.org</a><span style="color:#888888"><br>
</span><a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-<wbr>project.org/cgi-bin/mailman/<wbr>listinfo/rcpp-devel</a><u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal"><br>
<br clear="all">
<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal">-- <u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">Kyle Baron<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">Metrum Research Group<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><a href="tel:(860)%20735-7043" value="+18607357043" target="_blank">860-735-7043, Ext. 202</a><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><a href="mailto:kyleb@metrumrg.com" target="_blank"><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif">kyleb@metrumrg.com</span></a><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
<hr>
<p class="m_9094044376802374474{Imprint.UniqueID}" style="FONT-SIZE:8pt"><font face="Arial" size="1"></font></p>
<p class="m_9094044376802374474{Imprint.UniqueID}" style="FONT-SIZE:8pt"><font face="Arial"><strong>Confidentiality Notice:
</strong>This message is private and may contain confidential and proprietary information. If you have received this message in error, please notify us and remove it from your system and note that you must not copy, distribute or take any action in reliance
 on it. Any unauthorized use or disclosure of the contents of this message is not permitted and may be unlawful.</font></p>
<p class="m_9094044376802374474{Imprint.UniqueID}" style="FONT-SIZE:8pt"><font face="Arial"></font></p>
<p class="m_9094044376802374474{Imprint.UniqueID}" style="FONT-SIZE:8pt"><font face="Arial"></font></p>
<p class="m_9094044376802374474{Imprint.UniqueID}" style="FONT-SIZE:8pt"><font face="Arial"></font></p>
<p class="m_9094044376802374474{Imprint.UniqueID}" style="FONT-SIZE:8pt"><font face="Arial"></font></p>
<p class="m_9094044376802374474{Imprint.UniqueID}" style="FONT-SIZE:8pt"><font face="Arial"></font></p>
<p class="m_9094044376802374474{Imprint.UniqueID}" style="FONT-SIZE:8pt"><font face="Arial"></font><font size="+0"></font></p>
<p class="m_9094044376802374474{Imprint.UniqueID}" style="FONT-SIZE:8pt"><font face="Arial"></font></p>
<p class="m_9094044376802374474{Imprint.UniqueID}" style="FONT-SIZE:8pt"></p>
<p class="m_9094044376802374474{Imprint.UniqueID}" style="FONT-SIZE:8pt"></p>
</div>

<br>______________________________<wbr>_________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-<wbr>project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer" target="_blank">https://lists.r-forge.r-<wbr>project.org/cgi-bin/mailman/<wbr>listinfo/rcpp-devel</a><br></blockquote></div><br></div>