Accessing Snowflake with R

Snowflake is a well known cloud-based database. It’s used for Data Warehouses and other big data applications.

In this article and the following ones I want to show how to setup and access a snowflake database from various clients such as R, Tableau and PowerBI.

So let’s start using R.

Custom Formats in gt Tables

The “grammar of tables” is used to build tables with the R-package gt. Thomas Mock published an extension package called gtExtras which is used all over in tweets about NFL and Fantasy Football such as win and loss history information in a table.

gt follows a similar philosophy such as ggplot2. On the one hand there is the data to be shown (in a table resp. a plot). On the other hand there is the description how to visualize the data: What is the table header, are there subheaders, how are the cells grouped and formated?

So it was time to check out gt. During my tryouts I came across one demand I haven’t found an in-built solution for: I wanted to format a column with respect to the value of another column. Here’s the way I solved it:

Working with tree-based hierarchies using data.tree

Lately I tried to visualize an hierarchy with Tableau Desktop. The problem was that the hierarchy had a variable depth because it was tree-based. Each row had an id and a parent_id. Normally hierarchies in Tableau are defined by pulling some fields together, such as product category, product group and product id.

Handling tree-based hierarchies seems to be a lot more complex. I found a plugin at https://github.com/tableau/extension-hierarchy-navigator-sandboxed but this only works online.

So I asked myself how I can handle this using R. I found the R-package data.tree at https://github.com/gluc/data.tree. I want to describe how I use this package to preprocess my data.