Using Pipenv with R Markdown and reticulate

R Markdown is very nice way to write literate R code. Recently, [reticulate]( became available, which bridges R and Python in R Markdown documents.

If you use Pipenv for Python dependency management, here's how you get reticulate to use the proper Python executable:

venv <- system("pipenv --venv", inter = TRUE)
use_virtualenv(venv, required = TRUE)

The py_config() command should print out the path to the Python executable in the virtualenv created by Pipenv.