Minimum Viable Python — Working with Python

These articles contain guidance on how to incorporate Python into your data science workflow. They are not intended as general tips for all Python users, but rather as an articulation of what will work best if you primarily use R, occasionally use Python, and use Posit’s professional products.

REPL and shell

An important workflow difference if you’re coming from an R background is that most R work is done in the context of an interactive session, or REPL.

For example, to install a package in R, you can type the following:

R Console

> install.packages("dplyr")

and the dplyr package will be available for you to use.

By contrast, many of the Python commands you’ll see in this collection are intended to be run from the shell. For example, to install the Python package pandas, you would type the following

Terminal

$ python -m pip install pandas

Using the shell is discussed in an appendix of Happy Git With R.

The shell you are likely to be using depends on your operating system:

os shell
windows git-bash
macos zsh
linux bash

Environment Variables

Environment variables are named values that programs look up when they start or while they’re running. Variable names are capitalized by convention.

Setting environment variables

R startup

Place lists of environment variables in an .Renviron file. Read more about R startup in Chapter 7 of What They Forgot to Teach You About R.

Python startup

The python-dotenv package can be used to set environment variables from a .env file

Getting environment variables

Use Sys.getenv() in R, os.getenv() in Python, or printenv in the shell to get the value of an environment variable. HOME, for example, is the directory where most of your files will usually live.

Back to top