femiguez / apsimx

R package for APSIM-X
https://femiguez.github.io/apsimx-docs/
45 stars 19 forks source link

Accessing and Manipulating Values Extracted by inspect_apsimx #150

Closed matteolongo2 closed 3 months ago

matteolongo2 commented 3 months ago

Sorry for the basic question, how can I have access to the values extracted by inspect_apsimx? E.g.:

xxx <- inspect_apsimx("test.apsimx",
               root = "quadr_0_l_fodderbeet",
               node = "Operations",
               parm = list(18, 'Action'))

prints the table but does not save and let me work on the values. Specifically, I would like to extract all root names of a simualtion. Thank you

femiguez commented 3 months ago

@matteolongo2 I'm not sure I understand exactly what you need but you have a few options.

1) I was just working on improving functionality of the 'inspect_apsimx' function. The current version in github has several options when using 'node = "Other"'. For example, with the AgPasture.apsimx example:

inspect_apsimx("AgPasture.apsimx", src.dir = tmp.dir, node = "Other", parm = 1)
|   |first_level |second_level                         |
|:--|:-----------|:------------------------------------|
|1  |Simulations |DataStore                            |
|2  |.           |Memo                                 |
|3  |.           |AgPastureExample                     |
|4  |.           |Harvested Pasture by Production Year |
|5  |.           |PastureByWaterAndNitrogen            |
|6  |.           |CO2xBaseTemperature                  |
|7  |.           |CO2xHeatOnset                        |

This could store them in a list

  pp <- vector("list", length = 7)
  for(i in 1:7){
    pp[[i]] <- inspect_apsimx("AgPasture.apsimx", src.dir = tmp.dir, node = "Other", parm = list(1, i))
  }

However, your question is about 'Operations' and not 'Simulations', so maybe you are looking for the 'capture.output' function

femiguez commented 3 months ago

@matteolongo2 I added a function called 'extract_data_apsimx' it might be what you need. I'm closing this, but please start a new issue if you have any problems