Chapter 10 Further topics

This chapter is a collection of short section that show some of the very nice things you can use R for. These sections are based on past blog posts.

10.1 Using Python from R with {reticulate}

There is a lot of discussion online about the benefits of Python over and vice-versa. When it comes to data science, they are for the most part interchangeable. I would say that R has an advantage over Python when it comes to offering specialized packages for certain topics such as econometrics, bioinformatics, actuarial sciences, etc… while Python seems to offer more possibilities when it comes to integrating a machine learning model into an app. However, if most of your work is data analysis/machine learning, both languages are practically interchangeable. But it can happen that you need access to a very specific library with no R equivalent. Well, in that case, no need to completely switch to Python, as you can call Python code from R using the {reticulate} package.

{reticulate} allows you to seamlessly call Python functions from an R session. An easy way to use {reticulate} is to start a a new notebook, but you can also use {reticulate} and the included functions interactively. However, I find that Rstudio notebooks work very well for this particular use-case, because you can write R and Python chunks, and thus differentiate the different specific lines of code really well.

Let’s see how this works. First of all, you might need to specify the path to your Python executable, in my case, because I’ve installed Python using Anaconda, I need to specify it:

# This is an R chunk
use_python("~/miniconda3/bin/python")

10.2 Generating Pdf or Word reports with R

10.3 Scraping the internet

10.4 Regular expressions

10.5 Setting up a blog with {blogdown}