Replication of below article’s Data and Visualizations
“These Are the U.S. Universities Most Dependent on International Students”
By Emily Badger, Aatish Bhatia, Asmaa Elkeurtim Steven Rich and Ethan Singer”

Karim K. Kardous

Initial Setup

I start by configuring the Python environment using reticulate, specifying a custom virtual environment and ensuring required packages (matplotlib and pillow) are installed. This setup step ensures Python and R work seamlessly together; granted ‘seamlessly’ might be over-reaching, but at least for this case, fairly commonly used modules, it was the case.

Show the code
library(reticulate)
invisible(
  capture.output({
    Sys.setenv(RETICULATE_PYTHON = "py_venv/bin/python3.9")
    reticulate::use_python("py_venv/bin/python3.9", required = TRUE)
    })
)

invisible(
  capture.output({
  use_python("py_venv/bin/python3.9", required = TRUE)
  py_config()
  py_install(c('playwright', 'beautifulsoup4', 'pandas', 'plotnine'), envname = "py_venv", pip = TRUE)
  })
)
Show the code
system("py_venv/bin/python -m playwright install chromium")