R, Python: install packages on rpy2

Ricardo's answer no longer works.

To install from Python:

from rpy2.robjects.packages import importr
utils = importr('utils')

That utils package is the R.utils package whose documentation can be found here: https://CRAN.R-project.org/package=R.utils

As of my last edit, the documentation still says to do this.

When running pytest, Aaron's answer makes my Python hang and R keep giving error messages, probably because of this:

Calling install_packages() without first choosing a mirror will require the user to interactively choose a mirror.

According to rpy2 documentation, I used this which worked:

from rpy2 import robjects
import rpy2.robjects.packages as rpackages

utils = rpackages.importr('utils')
DirichletReg = rpackages.importr("DirichletReg")