Using Shiny with Scheduled and Streaming Data

Shiny applications are often backed by fluid, changing data. Data updates can occur at different time scales: from scheduled daily updates to live streaming data and ad-hoc user inputs. This article describes best practices for handling data updates in Shiny, and discusses deployment strategies for automating data updates. This post builds off of a 2017 rstudio::conf talk. The recording of the original talk and the sample code for this post are available.

Read more

Share Comments · · · · ·

Introduction to Visualizing Asset Returns

In a previous post, we reviewed how to import daily prices, build a portfolio, and calculate portfolio returns. Today, we will visualize the returns of our individual assets that ultimately get mashed into a portfolio. The motivation here is to make sure we have scrutinized our assets before they get into our portfolio, because once the portfolio has been constructed, it is tempting to keep the analysis at the portfolio level.

Read more

Share Comments · · · · ·

Automating Summary of Surveys with RMarkdown

This guide shows how to automate the summary of surveys with R and R Markdown using RStudio. This is great for portions of the document that don’t change (e.g., “the survey shows substantial partisan polarization”). The motivation is really twofold: efficiency (maximize the reusabililty of code, minimize copying and pasting errors) and reproducibility (maximize the number of people and computers that can reproduce findings). The basic setup is to write an Rmd file that will serve as a template, and then a short R script that loops over each data file (using library(knitr)).

Read more

Share Comments · · ·

Recent R Data Packages

It has never been easier to access data from R. Not only does there seem to be a constant stream of new packages that access the APIs of data providers, but it is also becoming popular for package authors to wrap up fairly large datasets into R packages. Below are 44 R packages concerned with data in one way or another that have made it to CRAN over the past two months.

Read more

Share Comments · · ·

September 2017 New Package Picks

There were so many interesting ideas among the 222 new packages that made it to CRAN in September that I found it exceptionally difficult to decide on the “Top 40” packages. In the end, I only managed to limit my selection to 40 by avoiding all packages that I would normally classify under “Data”: packages that are primarily intended to provide access to some data source. I hope to make up for this by providing a list of data packages sometime soon.

Read more

Share Comments · · ·

The SeaClass R Package

The SeaClass R Package The Operations Technology and Advanced Analytics Group (OTAAG) at Seagate Technology has decided to share an internal project that helps accelerate development of classification models. The interactive SeaClass tool is contained in an R-based package built using shiny and other CRAN packages commonly used for binary classification. The package is free to use and develop further, but any analysis mistakes are the sole responsibility of the user.

Read more

Share Comments · · · · · · ·

Database Queries With R

There are many ways to query data with R. This post shows you three of the most common ways: Using DBI Using dplyr syntax Using R Notebooks Background Several recent package improvements make it easier for you to use databases with R. The query examples below demonstrate some of the capabilities of these R packages. DBI. The DBI specification has gone through many recent improvements. When working with databases, you should always use packages that are DBI-compliant.

Read more

Share Comments · · · · · · · ·

Introduction to Portfolio Returns

Today, we go back a bit to where we probably should have started in the first place, but it wouldn’t have been as much fun. In our previous work on volatility, we zipped through the steps of data import, tidy and transformation. Let’s correct that oversight and do some spade work on transforming daily asset prices to monthly portfolio log returns. Our five-asset portfolio will consist of the following securities and weights:

Read more

Share Comments · · ·

Climate Change and Population Modeling in R

A recent paper in nature climate change: Less than 2°C warming by 2100 unlikely (Raftery et al. 2017), concludes that the goal of the Paris Agreement is unlikely to be met. Although the conclusion is disheartening, the paper advances the science of climate modeling by developing a joint Bayesian hierarchical model for Gross Domestic Product per capita and carbon intensity. This ensemble of models, in turn, depends on the availability of probabilistic population projections developed by the BayesPop Project at the University of Washington and available on CRAN.

Read more

Share Comments · · · · ·

WordR - A New R Package for Rendering Documents in MS Word Format

Motivation One day earlier this year, I was faced with the challenge of creating a report for management. It had to be an MS Word document (corporate requirement, you know). It was supposed to be polished and use many of the standard MS Word features like headers, footers, table of contents, and styles. I am not a Word guy, and besides, I wanted to make a reproducible document that would make it easy for me to include R code and plots in the text.

Read more

Share Comments · · · ·