Thursday, 14.06.2018
R , Julia, Python – todays data scientists have the choice between numerous different programming languages, each with their own strengths and weaknesses. Would it not be convenient to bring those languages together and use the individual strength of each language? The package “reticulate” for R takes a step in this direction.
The reticulate package creates a Python connection for R which enables the user to combine both languages for an optimal result. This tutorial referring to the Python engine for R Markdown implemented by reticulate, we will illustrate the basic idea, functionality and usefulness of the engine.
As an in-depth tutorial with examples and a fictional use case, we include an HTML notebook which is created in R Markdown. You can find it here.
The weapon of choice – data analysis in your day-to-day work
It could all be so simple: Everyone speaks the same language, borders blur and collaborations become easier than ever. What seems to sound a bit dramatic, happens more often in the everyday life of a data scientist. Even though R can show its strengths from a statistical point of view, Python, as a multi-purpose language, is becoming increasingly popular in the data science scene. Because of its multifunctionality, it is used more and more frequently the programming language of choice. Therefore, it seems necessary to build a bridge between both languages and create a common space within a project.
The virtual bridge – the reticulate package
The reticulate package provides a Python connection for R. Users can execute Python code directly from the R console, load Python scripts into the R environment and make them usable for R. In addition, reticulate provides a Python engine for R Markdown, which is described in the following example in more detail.
Introduction – setup & Python chunks in R Markdown
The setup of reticulate is very simple. After installing the package as well as the preferred distribution (2.7x or 3.x) you can
library(reticulate)
knitr::knit_engines$set(python = reticulate::eng_python)
install the Python engine. The chunks of code work as usual and every R chunk can be used for a Python chunk.
For example:
Get started now:
We look forward to engaging with you.