'Installing R "pegas" package using rpy2
I am trying to install the pegas R package using rpy2 but I am having trouble.
The error says 'The R package "pegas" is not installed'.
Could someone please direct me.
import rpy2
print(rpy2.__version__)
import rpy2.robjects as robjects
# import rpy2's package module
import rpy2.robjects.packages as rpackages
# R vector of strings
from rpy2.robjects.vectors import StrVector
# R package names
#Import R's pagas package
package_names = ('pegas')
if all(rpackages.isinstalled(x) for x in package_names):
have_package = True
else:
have_package = False
if not have_package:
# 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
# Selectively install what needs to be install.
# We are fancy, just because we can.
packnames_to_install = [x for x in package_names if not rpackages.isinstalled(x)]
if len(packnames_to_install) > 0:
utils.install_packages(StrVector(packnames_to_install))
pegas = rpackages.importr('pegas')
import rpy2.robjects.lib.pegas as pegas```
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
