Environments

Python environments

We encourage the use of virtual environments for your Python projects. This will help you avoid dependency conflicts between projects. This can be done using either venv or conda.

The instructors have developed a conda environment for this course that covers all the Python packages we plan to use during this semester. This environment is codifed in this YAML file: dsan5200.yml. (Right-click on this link to download the file)

You can install it using the following commands in a terminal (On Windows, with Anaconda/Miniconda installed, you can use the Anaconda Prompt CLI):

conda env create -f dsan5200.yml 

To use this environment, you can type the following command in the terminal:

conda activate dsan5200 

If you are using Visual Studio Code for your IDE, you can also select this environment as your Python interpreter. To do so, you can follow the instructions here.

Tip

This environment assumes that you have either Anaconda or Miniconda installed on your computer. If you don’t have either, you can download from the links. Miniconda is a more minimal installation; to understand which distribution would be right for you, you can see this page

Downloads are available for Windows, Mac (Intel and Silicon), and Linux.

R Environments

We encourage the use of virtual environments for your R projects. This will help you avoid dependency conflicts between projects. This can be done using renv. We do not recommend using conda for R projects, either to install R and R packages, or to maintain a virtual environment.

We encourage you to start using renv from the beginning of the semester. You can install it using the following command:

install.packages("renv") 

renv works best within RStudio Projects. We encourage you to have either one RStudio Project for the entire class, or create one Project for each assignment or laboratory. Within each project, you can create a renv environment using the following command:

renv::init() 

Using Python from R or R-driven Quarto

If you want to access the dsan5200 conda environment from R, you first install the reticulate package. Then, you can use packages in the dsan5200 environment by including the command

reticulate::use_condaenv("dsan5200", required=TRUE)` 

In a Quarto document, you can include this command in a R code chunk early in the document, and all subsequent Python code chunks will utilize this conda environment for its Python interpreter.

For more information, see the reticulate website, as well as Nicole Rennie’s excellent blog