ropensci / tradestatistics

R package to access Open Trade Statistics API
https://docs.ropensci.org/tradestatistics
Apache License 2.0
76 stars 14 forks source link

Add easy cache #29

Closed eliocamp closed 4 years ago

eliocamp commented 4 years ago

On your workshop you use manual caching of results with code like this

yr_rda <- "yr.rda"
if (!file.exists(yr_rda)) {
  yr <- ots_create_tidy_data(years = 2000:2018, reporters = "arg", table = "yr")
  save(yr, file =  yr_rda, compress = "xz")
} else {
  load(yr_rda)
}
yr

How about adding cache logic inside {tradestatistics}, This would make it easier for user to cache data and lighten the load on your servers. I implemented an example of cache logic that works both in memory (using {memoise}) and on disk here.

pachadotdev commented 4 years ago

Dear @eliocamp Please feel free to edit the code as you want but please send me a PR. Thanks a lot!!!!

pachadotdev commented 4 years ago

@eliocamp once again, thanks a lot for this suggestion I just discussed this with @jbkunst and he proposes that using memoise to save API caches in the server would be another cool improvement

eliocamp commented 4 years ago

Sounds cool. I'm not sure where those computations are performed (e.g. which repo).

Regarding this change, am I correct in that the only functions which make API requests are ots_create_tidy_data() and ots_read_from_api(). Those are the only ones that need cache?

pachadotdev commented 4 years ago

Dear @eliocamp I merged and closed #30. I did implemented some changes for consistent notation with the rest of the functions and I applied styler. So far, the only functionality I cannot get to work is in-memory caching, but caching on disk is working well.

vsoch commented 4 years ago

Should this be closed?

pachadotdev commented 4 years ago

Let me check if I fixed in-memory caching

On Sat, Dec 21, 2019, 9:38 PM Vanessasaurus notifications@github.com wrote:

Should this be closed?

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/ropensci/tradestatistics/issues/29?email_source=notifications&email_token=ACM7UOPGSAOY7R4AFQII5ILQZ2ZJ5A5CNFSM4J24P2Q2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEHPGJJY#issuecomment-568222887, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACM7UOMZIKYERWIZ4HYKBE3QZ2ZJ5ANCNFSM4J24P2QQ .

pachadotdev commented 4 years ago

closed, sent to CRAN with an edited version of these changes (v0.2.7) https://cran.r-project.org/web/packages/tradestatistics/index.html