Trying to add file output to wolfAlps module

Skip to first unread message

Jul 25, 2018, 6:37:14 AM7/25/18
to SpaDES Users
I am trying to add a file output to the SpaDES wolfAlps module. Since I am new to R in general and of course to SpaDES /NetLogo .. as well, this might be a really obvious question for most of you, so I am sorry about that.

In the preamble is some outputObjects prepared, but the variables are empty and even if I add something it doesn't seem to do anything:

outputObjects = data.frame(
objectName = NA_character_,
objectClass = NA_character_,
other = NA_character_,
stringsAsFactors = FALSE

So I tried to find something in the documentation. The most detailed description I could find is this one:
but it seems outdated to me (?). Or can I do it that way?

There is a lot of documentation about caching, and if I where a really advanced user I would certainly try that - but I think I would really like to have files as output that I can read with a simple editor and maybe do some of the analysis without R.. and caching does not work that way, right?

Then, there is this part about saving: Saving
Several information about wolves and packs is saved during the simulation. 9 outputs objects store them (out_terrSize, out_deaths, out_statPack, out_statInd, out_distDisp, out_statSim, out_terr, out_joinCreate, out_dispersers).
But it is within the program, right? And can be passed to plotting, for example.

So if there is another documentation page that I haven't found yet, or if you can tell me where else to look, I would be very grateful.

Thanks, Clara


Jul 25, 2018, 7:19:30 AM7/25/18
to SpaDES Users

Once you ran the module with wolfAlpsOutput <- spades(wolfModuleInit), you can access to the ouputs using wolfAlpsOutput$out_terrSize, wolfAlpsOutput$out_deaths, etc...

You can access using wolfAlpsOutput$... to any R objects that is defined as sim$... in the module (out_terrSize, out_deaths, etc. but also the maps, wolves, etc.).

If you want to create a new output, code for it in the module using
sim$myNewOuput <- ...
Then, code in the module to update it as you want during the simulation and then you can retrieve it at the end of the simulation with wolfAlpsOutput$myNewOuput and save it using R functions (save(), writeRaster(), write.csv(), etc.).

I hope this answer your question!


Jul 26, 2018, 5:32:21 AM7/26/18
to SpaDES Users
Thank you, Sarah, you helped a lot :) I have been wondering forever where exactly those outputs go. I can definitely work with that.

Out of curiosity: why didn't you use saveFiles / .saveObjects from the SpaDES package? This seems to be very elegant, even though I don't quite get how it is supposed to work.


Jul 26, 2018, 5:37:37 AM7/26/18
to SpaDES Users
My answer is in your question: "I don't quite get how it is supposed to work" ;) :)
And using wolfAlpsOutput$outputName was really easy.
Glad I could help!


Eliot McIntire

Jul 26, 2018, 4:05:42 PM7/26/18
to SpaDES Users
If you list objects in .saveObjects, then saveFiles will save them. It is "easy" because you don't have to write one line for every object to save ... saveFiles will save them all.

More easy, in my perspective is use "outputs", where you can schedule which objects to save, and when. The below would save 2 objects every year of the years 1 to 200. Very compact.

mySim <- simInit(..., outputs = data.frame(
     expand.grid(objectName = c("caribou","landscape"),
     saveTime = 1:200,
     stringsAsFactors = FALSE), ...)

mySimOut <- spades(mySim)

Then to see what and where they are, you do outputs(mySim), and you see a data.frame of all the objects that were saved, and all their file names, all in one place.

Aug 1, 2018, 6:58:45 AM8/1/18
to SpaDES Users
Not sure I quite got it, though:
1) Are there three different methods to save outputs?
a. The way Sarah did it in the wolfAlps module
b. The way you described above using outputs
c. Using .saveObjects combined with .saveFiles
Or is a=b somehow?
2) Is b the same as the "1.Model-level saving" described in the documentation of saveFiles [?saveFiles()]? If so, where does the .saveFiles come in? Or is the saveFiles function not used in this case? If so, why does this case appear in the saveFiles documentation?
3) Is c the same as "2.Module-level saving" in the saveFiles documentation?
4) Is there a reason why I shouldn't use a but b or c instead?
Thanks, Clara
Reply all
Reply to author
0 new messages