ncsu-landscape-dynamics / rpops

PoPS (Pest or Pathogen Spread) R Package
https://ncsu-landscape-dynamics.github.io/rpops/
GNU General Public License v3.0
10 stars 5 forks source link

add option to save ouputs in functions #108

Closed nkruskamp closed 3 years ago

nkruskamp commented 3 years ago

I know we're trying to reduce the number of function parameters, but I wanted to discuss the option to incorporate an option to save outputs natively in function execution instead of only returning an R object.

The use case is when someone needs to execute functions in CLI or other non-interactive sessions, they may want items saved to disk. Currently, certain objects (e.g. terra spatRast objects) cannot be saved as Rdata and need to be saved individually.

Currently, I do the following example:

multirun_results <- pops_multirun(...)

`dst_img_path <- ffOut("probability.tif"))
terra::writeRaster(multirun_results$probability, dst_img_path, overwrite = TRUE)

dst_img_path <- ffOut("simulation-mean.tif"))
terra::writeRaster(multirun_results$simulation_mean, dst_img_path,
  overwrite = TRUE
)

dst_img_path <- ffOut("_simulation-sd.tif"))
terra::writeRaster(multirun_results$simulation_sd, dst_img_path,
  overwrite = TRUE
)

dst_img_path <- ffOut("_simulation-max.tif"))
terra::writeRaster(multirun_results$simulation_max, dst_img_path,
  overwrite = TRUE
)

dst_img_path <- ffOut("_simulation-min.tif"))
terra::writeRaster(multirun_results$simulation_min, dst_img_path,
  overwrite = TRUE
)

data_path_rdata <- ffOut("_multirun-data.rdata"))
save(multirun_results, file = data_path_rdata)`

This could be incorporated into the function that might provide a destination folder for outputs.