Databases – an Ideal Application for R6?
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.
R-bloggers.com 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.