ELSA-UNDP / elsar

Creative Commons Attribution 4.0 International
1 stars 0 forks source link

Write wrapper function for fetching data #3

Open sandra-neubert opened 3 months ago

sandra-neubert commented 3 months ago

It would be easier to have one function that takes in a vector of the wanted datasets, calls the functions for getting/generating these datasets and combines it to one output file, rather than having to list the individual functions that are wanted each time. What do you think @scabecks ?

scabecks commented 3 months ago

Do you have a dummy code example of what you're thinking?

sandra-neubert commented 3 months ago

Yes, this would be for example:

get_wanted_data <- function(wantedData, someMoreSettingsForSomeDatasets) {
if (certified_forests %in% wantedData) {
certifiedForestAreas <- get_certified_forests() }
if (flood_risk_areas %in% wantedData) {
floodRiskAreas <- get_flood_risk_areas() }
...
stackedData <- c(certifiedForestAreas, floodRiskAreas, ...)
}

And then in the script that you're actually working in you just need to run to get all the data you want: allWantedData <- get_wanted_data(wantedData = c(certified_forests, flood_risk_areas), someMoreSettingsForSomeDatasets) Instead of for every new project listing all the indiviual functions, e.g.:

certifiedForestAreas <- get_certified_forests() 
floodRiskAreas <- get_flood_risk_areas() 

etc.

Does this make sense @scabecks ?

scabecks commented 3 months ago

Lovely! Perfect sense!