Thanks for all your helpful and prompt replies. I just composed a long message but when I clicked submit my login had timed out and I lost it all! So I will try to remember what I had written.
Firstly, I totally agree with the "R" as a name issue. It makes it SO difficult to search for relevant help.
Administrator wrote:I tried this earlier, it fails at the first hurdle (will not load the DLL). Both x32 and x64 failed.
I get a different issue. I can load the vendll32.dll using dyn.load() in R. I can then check that this is loaded using getLoadedDLLs(), which confirms that vendll32 is loaded, and that Dynamic.Lookup=TRUE. (I have installed Rtools developer tool package, which may make a difference here.)
However, if I then try to use any of the C commands in the dll using the .C( ) command in R (for example .C("vensim_command","FILE>EXISTS|RABFOX.vpm",PACKAGE="vendll32") ) it crashes R: "R encountered a fatal error. The session was terminated." It is definitely interacting with the DLL though, as if I use a command that is not in there is comes back with: "nonexistent_vensim_command" not available for .C() for package "vendll32".
tomfid wrote:It should be straightforward to write an R package that wraps Vensim, if it hasn't been done.
I think this might be the way to go. I don't think I have the know-how to do this unfortunately. I will try contacting Jim Duggan, as he has just published a book called "Systems Dynamics in R", so may have worked out what can and can't be done.
Big picture, I am wanting to set values for model parameters (read cin file), run the vensim model for a year then get values at the end of the year (at double-precision), use those values as inputs to a model written in R code, then use values the R code calculates to set values for the Vensim model and then run it for another year. I tried running the model one year at a time and using the final time values of stocks as initial conditions for the next year's run, but due to the scaling in my model the exported values being only 6sf accuracy led to very different behaviour. This led me to the conclusion that I need to run the model in gaming mode in 1 year intervals, using get_dpval and set_val. This means I can't use the batch command file approach.
I should note that I am not wed to R, so if there is an implementation in Python that would work for me I think. I know I can call R code from Python, so I could use Python as the bridge/integrator between the models. I haven't found any python code for this in my searches yet. Anyone have any links to where this has been done?