Programming with Python with reticulate

Introduction to using Python in R and the reticulate package
Author
Affiliation

Department of Biostatistics, Johns Hopkins

Published

December 10, 2024

Pre-lecture activities

Important

In advance of class, please install:

  • reticulate - this provides an interface between R and python

You can do this by calling

install.packages(c("reticulate"))

In addition, please read through the pre-reading:

And if there is time, these are useful too:

  1. https://rstudio.github.io/reticulate
  2. https://py-pkgs.org/02-setup
  3. The Python Tutorial
  4. https://docs.posit.co/ide/user/ide/guide/environments/py/python.html

Lecture

Acknowledgements

Material for this lecture was borrowed and adopted from

Learning objectives

Learning objectives

At the end of this lesson you will:

  1. Install the reticulate R package on your machine (I’m assuming you have python installed already)
  2. Learn about reticulate to work interoperability between Python and R
  3. Be able to translate between R and Python objects

Slides

Class activity

For the rest of the time in class, you and your team will work on the final project. Stephanie will walk around to answer questions and to help in anyway I can.

Post-lecture

Additional practice

Here are some additional practice questions to help you think about the material discussed.

Questions
  1. Try to use tab completion for a function.
  2. Try to install and load a different python module in R using import().