Page 1 of 1

VENSIM output data from R

Posted: Mon Jun 07, 2021 10:30 am
by morebru
Hello,

Is there a way of obtaining output data from a vdf file like the function vensim_get_data() function, but insted of using Excel, using R? Besides, is there a way of converting a .tab file to a .vdf file using R?

Thanks.

Re: VENSIM output data from R

Posted: Mon Jun 07, 2021 2:38 pm
by Administrator
Can you explain what you need to do?

You can export a VDF to CSV, TAB etc. You can also convert CSV, TAB etc to VDF. I'm sure R can read CSV and TAB files.

Re: VENSIM output data from R

Posted: Tue Jun 08, 2021 9:16 am
by morebru
I would like to launch Vensim authomatically from R for testing many parameters in my model. For this, I need to create a .cmd file which will read a .vdf. From R I can create a .tab file without problem, but it must be read by Vensim, so that the .tab file must be converted to .vdf format. Is there a way of doing this from R? Another task I need to do would be to read the model outputs that are in .vdf format into R. From Excel is it possible to do it using the vensim_get_data() function. I was wonderig if it is possible to build a similar function in R to extract outputs from a .vdf file.

Re: VENSIM output data from R

Posted: Tue Jun 08, 2021 9:39 am
by Administrator
Vensim can read TAB files as well.
http://www.vensim.com/documentation/fn_ ... _data.html

Or you can convert the TAB file before using it,
http://www.vensim.com/documentation/tab2vdf.html

And if you are launching Vensim via a command file, you can export the results once the simulation is finished. I'm guessing as you haven't uploaded anything for us to see, I'm assuming you have something like the following in your command file.
SPECIAL>LOADMODEL|mymodel.mdl
MENU>RUN!o

You can add the following after the MENU>RUN command
MENU>VDF2TAB|vdffile|tabfile

and read that back into R.

So the following would load a model, import a tab file, run it and export the VDF to a TAB.

MENU>TAB2VDF|mytabfile.tab|myvdffile.vdfx
SPECIAL>LOADMODEL|mymodel.mdl
MENU>RUN!o
MENU>VDF2TAB|myrun.vdfx|myrun.tab


Relevant links,
http://www.vensim.com/documentation/vdf2tab.html
http://www.vensim.com/documentation/tab2vdf.html

Re: VENSIM output data from R

Posted: Tue Jun 08, 2021 1:03 pm
by morebru
That is exactly what I nedded. Thanks a lot.

Re: VENSIM output data from R

Posted: Fri Jun 11, 2021 11:38 am
by SionC
Hi morebru - are you running the command files from R? I have been trying to run simulations using R via the Vensim dll but I am not having much success!

Re: VENSIM output data from R

Posted: Fri Jun 11, 2021 2:17 pm
by morebru
Hi SionC, neither am I. I am trying to automatize some runs but without much success so far.

Re: VENSIM output data from R

Posted: Fri Jun 11, 2021 2:38 pm
by Administrator
If either of you can share some code, I can try. I've never used R before, but should be able to figure out how to do things.

Re: VENSIM output data from R

Posted: Sat Jun 12, 2021 8:41 am
by SionC
Hi - Great. I'll can set up a GIT repository next week and we can share things that way if that sounds like a good way ahead.