ropensci / awardFindR

Scan multiple online grant databases for relevant awards
https://docs.ropensci.org/awardFindR
Other
16 stars 7 forks source link

Restructure API functions / apis.R #14

Closed adam3smith closed 3 years ago

adam3smith commented 3 years ago

As per discussion on 2/8: Restructure the apis.R function to be a simple loop/lapply through all sources and move the code that standardizes output into a separate function in the same file as the api_get function. So, e.g., the arnold.R file would contain two functions: arnold_get() and arnold_standardize().

adam3smith commented 3 years ago

Nice work on this @mccallc ! Do you think we could simplify this further? I'm thinking something along the lines of

for (source in sources) {
    results <- eval(parse(text = paste0('rbind.data.frame(results, ', source, '_standardize(keywords, from_year, to_year))')))  
}    

i.e. automatically generate the function name

mccallc commented 3 years ago

I knew there had to be a way to dynamically interpret function names. This is definitely the most elegant and scalable solution. I'll move date handling and multiple keyword looping to the source R files from main.R so all the *_standardize() functions can handle the exact same input, then this should be feasible

mccallc commented 3 years ago

Fully implemented in commit 0a323b8f563e9f926e1ebdf9ba14eb4387b6d874