'Using rpy2 to install additional packages failing from jupyter lab

I am trying to call R from within some python code using the rpy2 library. I need to use non-base packages, but keep on running into the following hiccup. Thanks for considering! Most of the code is copy-pasted from the manual.

import rpy2
import rpy2.robjects as robjects
from rpy2.robjects.packages import importr

# import rpy2's package module
import rpy2.robjects.packages as rpackages

base = importr('base')

# import R's utility package

utils = rpackages.importr('utils')

# select a mirror for R packages
utils.chooseCRANmirror(ind=1) # select the first mirror in the list


# R package names
packnames = ('pROC', 'bootLR')

# R vector of strings
from rpy2.robjects.vectors import StrVector

# Selectively install what needs to be install.
# We are fancy, just because we can.
names_to_install = [x for x in packnames if not rpackages.isinstalled(x)]
if len(names_to_install) > 0:
    utils.install_packages(StrVector(names_to_install))
    
importr('bootLR')

Gives error

---------------------------------------------------------------------------
RRuntimeError                             Traceback (most recent call last)
<ipython-input-27-359b2847dddf> in <module>
      1 utils.install_packages("bootLR")
----> 2 importr('bootLR')

~/opt/anaconda3/lib/python3.7/site-packages/rpy2/robjects/packages.py in importr(name, lib_loc, robject_translations, signature_translation, suppress_messages, on_conflict, symbol_r2python, symbol_check_after, data)
    451     if _package_has_namespace(rname, 
    452                               _system_file(package = rname)):
--> 453         env = _get_namespace(rname)
    454         version = _get_namespace_version(rname)[0]
    455         exported_names = set(_get_namespace_exports(rname))

RRuntimeError: Error in loadNamespace(name) : there is no package called ‘bootLR’```



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source