Logo

The Data Daily

Library Code | R-bloggers

Library Code | R-bloggers

Matt KayeR-bloggershereclick herehere [This article was first published on , 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.

By definition, library code is code that’s written to being reused by programs other than itself that are unrelated to each other. For instance, (R) and (Python) are common examples of library code: Instead of writing code from scratch to work with tabular data, you might use one of those two fantastic libraries. And you get some additional benefits from using them: Those libraries are well-documented, so it’s easy to figure out how to use them. They’re well-tested, so you (presumably) know that bugs are less likely than if you were to try to write the same functionality from scratch. They’re widely used, so it’s easy to find answers to questions and get help from the communities using them.

At CollegeVine, we have : An R package containing a lot of code that we use very often for all kinds of analytics projects. Some things that live in include: Plot theming code, so that we can consistently theme graphics across all of our work. A custom implementation of item-based collaborative filtering, which is core to our school recommendation system. and wrappers for connecting to and querying our databases and working with data in S3. Helper methods for common math we do, such as converting between odds, log-odds, and probabilities. Miscellaneous helper code for things that don’t exist natively in R, such as for removing an item from a list and , the inverse of the operator. An implementation of the Brier Skill Score, which is a metric we often use for evaluating classification models. You might think of as being a common library of things that our team does often, so we don’t need to repeat ourselves or reinvent the wheel. Let’s imagine that you’re setting up a common library (in this example, an R package) for your team. The first thing you might want to do is have some logic to help your team connect to your data warehouse. For this example, let’s just imagine that “warehouse” is your local Postgres instance. Then, you might write a method for your library called like this: library(DBI)
library(rlang)
library(httr)
library(RPostgres)

connect_to_dwh

Images Powered by Shutterstock