Menu Close

Example of calling external R script from ST-Sim

Syncrosim Forums ST-Sim & State-and-Transition Simulation Models Example of calling external R script from ST-Sim

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #7065

    Hello, it seems to be possible to make calls to an external R script from ST-Sim (from the “external program” pane in the advanced tab in the scenario properties). Would it be possible to maybe get a working example of a script to get an idea of how it would be written and implemented with rsynchrosim? For instance in order to perform some operation on state attribute values between time steps.

    Thanks in advance!

    Leonardo FridLeonardo Frid

    Hi Val,

    I have posted an example of how to do this here:

    This example works with a minimum of SyncroSim 2.0.42, ST-Sim 3.1.42, and rsyncrosim 1.0.6. It should be forward compatible to future versions.

    Note that to run this on the scenario properties under “Advanced | External Program” you need to point to the correct locations for the “externalProgramScript.R” file that is included in the zip as well as the correct location for your Rscript.exe, usually found in “…/Program Files/R/R-VERSION/bin/”.

    There are two scenarios in the library, the first does not use the external program and the second does. In this example, the external program makes timber harvest conditional on the amount of a state attribute (ungulate winter habitat). The first scenario targets 10,000 acres of harvest per year. The second scenario makes this target conditional on habitat being above 12,000 acres, otherwise it sets the harvest target to 0.


    Colin DanielColin Daniel

    Note that you can also access the External Program feature directly from R (using the rsyncrosim package) or the SyncroSim Console (i.e. using SyncroSim.Console.Exe) through the datasheet named STime_External

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.