An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-ecology/attachments/20110609/235abfdc/attachment.pl>
Packaging simecol object into package
2 messages · Rainer M Krug, Thomas Petzoldt
Dear Rainer, there are several methods to do this and they are, in principle, described in Section 1.3 of the simecol vignette "Dierent ways to store simObjects". 1) In package simecol, all example objects are simply stored as .Rdata in the /data directory. Just create your objects, then run package.skeleton() and move the data objects to your package. However, method (1) had some drawbacks, therefore: 2) in package simecolModels, I use a "generator" function (see example below), similarly to your makeASM() idea. The package simecolModels, that is available from R-Forge http://r-forge.r-project.org/projects/simecol/ (or http://www.simecol.de). may serve as a template. Hope it helps Thomas genLV <- function() { new("odeModel", main = function(time, x, p) { dx1 <- p["k1"] * x[1] - p["k2"] * x[1] * x[2] dx2 <- -p["k3"] * x[2] + p["k2"] * x[1] * x[2] list(c(dx1, dx2)) }, parms = c(k1 = 0.2, k2 = 0.2, k3 = 0.2), times = c(from = 0, to = 100, by = 0.5), init = c(prey = 0.5, predator = 1), solver = "lsoda") } Now, the function contains the instruction, how R can create a new instance of such a model. The simecol object is not created yet, but a call to the creator function can bring it to live: lv1 <- genLV() plot(sim(lv1))
Dr. Thomas Petzoldt (limnology and ecological modelling) Technische Universitaet Dresden Faculty of Forest, Geo and Hydro Sciences Institute of Hydrobiology 01062 Dresden, Germany E-Mail: thomas.petzoldt at tu-dresden.de http://tu-dresden.de/Members/thomas.petzoldt