Databases – an Ideal Application for R6?

[This article was first published on Quintuitive » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Over the years I have tried to simplify and streamline my access to financial historic data. All different solutions I tried (see here, for example) so far have been unsatisfactory, at least to some degree. That however changed after I started using R6. Here is an example of using the R6 class for the same task as before:

ydb = YahooDb$new("~/yahoo.db")
# "g" is just a shortcut for "get.symbol"
spy = ydb$g("spy")

The advantage of using objects comes handy to keep relevant things logically coupled, to simplify the API and to minimize the external configuration (not too obvious when using SQLite, but try using a database server, like MySQL where we have to deal with a URL, user, password, etc). As in the older version, the above code first checks the database, and only if the symbol requested is not available there, it requests the data from Yahoo Finance. Notice, the database format is different from what quantmod uses. In my version, all daily data is stored into a single table.

Last, I added the YahooDb class to the btutils package, where the code will be kept up-to-date.

The post Databases – an Ideal Application for R6? appeared first on Quintuitive.

To leave a comment for the author, please follow the link and comment on their blog: Quintuitive » R. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)