pythonrinstallationpackagerpy2

How to install this R-Package 'rcompanion' on Python?


I would like to know how to install the R package 'rcompanion' on Python. I have been able to install other R packages, this particular 'rcompanion' does not appear to install correctly.

See doc here

What I have done so far :

What I expect :

for rcompanion to get installed

What happened :

rcompanion is not installing, with following error message /traceback

PackageNotInstalledError                  Traceback (most recent call last)
Cell In[12], line 17
     14 utils.install_packages('https://cran.r-project.org/src/contrib/Archive/rcompanion/rcompanion_2.4.26.tar.gz')
     16 # Load packages
---> 17 rcompa = importr('rcompanion')
     18 hunspell = importr('hunspell')

File D:\bigar\Anaconda\Lib\site-packages\rpy2\robjects\packages.py:472, in importr(name, lib_loc, robject_translations, signature_translation, suppress_messages, on_conflict, symbol_r2python, symbol_resolve, data)
    440 """ Import an R package.
    441 
    442 Arguments:
   (...)
    468 
    469 """
    471 if not isinstalled(name, lib_loc=lib_loc):
--> 472     raise PackageNotInstalledError(
    473         'The R package "%s" is not installed.' % name
    474     )
    476 if suppress_messages:
    477     ok = quiet_require(name, lib_loc=lib_loc)

PackageNotInstalledError: The R package "rcompanion" is not installed.

My code :

PackageNotInstalledError: The R package "rcompanion" is not installed.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import seaborn as sns
import statsmodels
import geostatspy.GSLIB as gslib
import geostatspy.geostats as geostats
import scipy.stats
import skgstat as skg


# Using R inside python
import os
os.environ['R_HOME'] = r"D:\bigar\Anaconda\Lib\R"

import rpy2
import rpy2.robjects.packages as rpackages
from rpy2.robjects.vectors import StrVector
from rpy2.robjects.packages import importr
utils = importr('utils')
utils.chooseCRANmirror(ind=1)

# Install packages
utils.install_packages('DescTools')
utils.install_packages('https://cran.r-project.org/src/contrib/Archive/rcompanion/rcompanion_2.4.26.tar.gz')

# Load packages
rcompa = importr('rcompanion')

enter image description here

IOther code attempt, same error.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import seaborn as sns
import statsmodels
import geostatspy.GSLIB as gslib
import geostatspy.geostats as geostats
import scipy.stats
import skgstat as skg


# Using R inside python
import os
os.environ['R_HOME'] = r"D:\bigar\Anaconda\Lib\R"

import rpy2
import rpy2.robjects.packages as rpackages
from rpy2.robjects.vectors import StrVector
from rpy2.robjects.packages import importr
utils = importr('utils')
utils.chooseCRANmirror(ind=1)

# Install packages
utils.install_packages('DescTools')
utils.install_packages('rcompanion')

# Load packages
rcompa = importr('rcompanion')

enter image description here


Solution

  • Problem solved.

    I installed R on my computer, then wrote

     os.environ['R_HOME'] = r'C:\Program Files\R\R-4.4.1'
    

    and

    utils.install_packages('rcompanion')
    

    It worked, the package is now installed. See below for full code and result

    Code :

    # Using R inside python
    import os
    os.environ['R_HOME'] = r'C:\Program Files\R\R-4.4.1'
    
    import rpy2
    import rpy2.robjects.packages as rpackages
    from rpy2.robjects.vectors import StrVector
    from rpy2.robjects.packages import importr
    utils = importr('utils')
    utils.chooseCRANmirror(ind=1)
    
    # Install packages
    utils.install_packages('hunspell')
    utils.install_packages('rcompanion')
    
    # Load packages
    rcompa = importr('rcompanion')
    hunspell = importr('hunspell')
    

    Result

    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/hunspell_3.0.3.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 1512974 bytes (1.4 MB)
    
    R[write to console]: downloaded 1.4 MB
    
    
    package 'hunspell' successfully unpacked and MD5 sums checked
    
    The downloaded binary packages are in
        C:\Users\bigar\AppData\Local\Temp\RtmpqOtrZ8\downloaded_packages
    R[write to console]: also installing the dependencies 'glue', 'utf8', 'sys', 'proxy', 'rematch', 'fansi', 'lifecycle', 'magrittr', 'pillar', 'pkgconfig', 'rlang', 'vctrs', 'crayon', 'hms', 'prettyunits', 'askpass', 'rootSolve', 'e1071', 'lmom', 'cellranger', 'tibble', 'cpp11', 'progress', 'curl', 'jsonlite', 'mime', 'openssl', 'R6', 'TH.data', 'sandwich', 'mvtnorm', 'expm', 'rstudioapi', 'Exact', 'gld', 'data.table', 'readxl', 'httr', 'withr', 'cli', 'libcoin', 'matrixStats', 'modeltools', 'multcomp', 'zoo', 'DescTools', 'multcompView', 'plyr', 'coin', 'lmtest', 'nortest'
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/glue_1.7.0.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 163516 bytes (159 KB)
    
    R[write to console]: downloaded 159 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/utf8_1.2.4.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 150988 bytes (147 KB)
    
    R[write to console]: downloaded 147 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/sys_3.4.2.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 47898 bytes (46 KB)
    
    R[write to console]: downloaded 46 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/proxy_0.4-27.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 181201 bytes (176 KB)
    
    R[write to console]: downloaded 176 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/rematch_2.0.0.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 19277 bytes (18 KB)
    
    R[write to console]: downloaded 18 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/fansi_1.0.6.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 323451 bytes (315 KB)
    
    R[write to console]: downloaded 315 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/lifecycle_1.0.4.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 141047 bytes (137 KB)
    
    R[write to console]: downloaded 137 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/magrittr_2.0.3.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 229422 bytes (224 KB)
    
    R[write to console]: downloaded 224 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/pillar_1.9.0.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 663048 bytes (647 KB)
    
    R[write to console]: downloaded 647 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/pkgconfig_2.0.3.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 22827 bytes (22 KB)
    
    R[write to console]: downloaded 22 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/rlang_1.1.4.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 1622822 bytes (1.5 MB)
    
    R[write to console]: downloaded 1.5 MB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/vctrs_0.6.5.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 1360958 bytes (1.3 MB)
    
    R[write to console]: downloaded 1.3 MB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/crayon_1.5.3.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 165502 bytes (161 KB)
    
    R[write to console]: downloaded 161 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/hms_1.1.3.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 105599 bytes (103 KB)
    
    R[write to console]: downloaded 103 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/prettyunits_1.2.0.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 155311 bytes (151 KB)
    
    R[write to console]: downloaded 151 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/askpass_1.2.0.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 74676 bytes (72 KB)
    
    R[write to console]: downloaded 72 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/rootSolve_1.8.2.4.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 694264 bytes (677 KB)
    
    R[write to console]: downloaded 677 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/e1071_1.7-14.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 671840 bytes (656 KB)
    
    R[write to console]: downloaded 656 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/lmom_3.0.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 579663 bytes (566 KB)
    
    R[write to console]: downloaded 566 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/cellranger_1.1.0.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 106542 bytes (104 KB)
    
    R[write to console]: downloaded 104 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/tibble_3.2.1.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 695404 bytes (679 KB)
    
    R[write to console]: downloaded 679 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/cpp11_0.4.7.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 304569 bytes (297 KB)
    
    R[write to console]: downloaded 297 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/progress_1.2.3.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 88589 bytes (86 KB)
    
    R[write to console]: downloaded 86 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/curl_5.2.1.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 3219552 bytes (3.1 MB)
    
    R[write to console]: downloaded 3.1 MB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/jsonlite_1.8.8.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 1107194 bytes (1.1 MB)
    
    R[write to console]: downloaded 1.1 MB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/mime_0.12.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 40893 bytes (39 KB)
    
    R[write to console]: downloaded 39 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/openssl_2.2.0.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 3398930 bytes (3.2 MB)
    
    R[write to console]: downloaded 3.2 MB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/R6_2.5.1.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 85007 bytes (83 KB)
    
    R[write to console]: downloaded 83 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/TH.data_1.1-2.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 8827582 bytes (8.4 MB)
    
    R[write to console]: downloaded 8.4 MB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/sandwich_3.1-0.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 1514218 bytes (1.4 MB)
    
    R[write to console]: downloaded 1.4 MB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/mvtnorm_1.2-5.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 780993 bytes (762 KB)
    
    R[write to console]: downloaded 762 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/expm_0.999-9.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 216960 bytes (211 KB)
    
    R[write to console]: downloaded 211 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/rstudioapi_0.16.0.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 338646 bytes (330 KB)
    
    R[write to console]: downloaded 330 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/Exact_3.3.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 205151 bytes (200 KB)
    
    R[write to console]: downloaded 200 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/gld_2.6.6.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 243600 bytes (237 KB)
    
    R[write to console]: downloaded 237 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/data.table_1.15.4.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 2416893 bytes (2.3 MB)
    
    R[write to console]: downloaded 2.3 MB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/readxl_1.4.3.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 1202473 bytes (1.1 MB)
    
    R[write to console]: downloaded 1.1 MB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/httr_1.4.7.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 495535 bytes (483 KB)
    
    R[write to console]: downloaded 483 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/withr_3.0.1.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 230867 bytes (225 KB)
    
    R[write to console]: downloaded 225 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/cli_3.6.3.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 1361839 bytes (1.3 MB)
    
    R[write to console]: downloaded 1.3 MB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/libcoin_1.0-10.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 816564 bytes (797 KB)
    
    R[write to console]: downloaded 797 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/matrixStats_1.3.0.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 552782 bytes (539 KB)
    
    R[write to console]: downloaded 539 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/modeltools_0.2-23.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 225349 bytes (220 KB)
    
    R[write to console]: downloaded 220 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/multcomp_1.4-26.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 736477 bytes (719 KB)
    
    R[write to console]: downloaded 719 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/zoo_1.8-12.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 1028644 bytes (1004 KB)
    
    R[write to console]: downloaded 1004 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/DescTools_0.99.55.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 5782180 bytes (5.5 MB)
    
    R[write to console]: downloaded 5.5 MB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/multcompView_0.1-10.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 117247 bytes (114 KB)
    
    R[write to console]: downloaded 114 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/plyr_1.8.9.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 1107711 bytes (1.1 MB)
    
    R[write to console]: downloaded 1.1 MB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/coin_1.4-3.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 1469969 bytes (1.4 MB)
    
    R[write to console]: downloaded 1.4 MB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/lmtest_0.9-40.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 410118 bytes (400 KB)
    
    R[write to console]: downloaded 400 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/nortest_1.0-4.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 39477 bytes (38 KB)
    
    R[write to console]: downloaded 38 KB
    
    
    R[write to console]: trying URL 'https://cloud.r-project.org/bin/windows/contrib/4.4/rcompanion_2.4.36.zip'
    
    R[write to console]: Content type 'application/zip'
    R[write to console]:  length 653768 bytes (638 KB)
    
    R[write to console]: downloaded 638 KB
    
    
    package 'glue' successfully unpacked and MD5 sums checked
    package 'utf8' successfully unpacked and MD5 sums checked
    package 'sys' successfully unpacked and MD5 sums checked
    package 'proxy' successfully unpacked and MD5 sums checked
    package 'rematch' successfully unpacked and MD5 sums checked
    package 'fansi' successfully unpacked and MD5 sums checked
    package 'lifecycle' successfully unpacked and MD5 sums checked
    package 'magrittr' successfully unpacked and MD5 sums checked
    package 'pillar' successfully unpacked and MD5 sums checked
    package 'pkgconfig' successfully unpacked and MD5 sums checked
    package 'rlang' successfully unpacked and MD5 sums checked
    package 'vctrs' successfully unpacked and MD5 sums checked
    package 'crayon' successfully unpacked and MD5 sums checked
    package 'hms' successfully unpacked and MD5 sums checked
    package 'prettyunits' successfully unpacked and MD5 sums checked
    package 'askpass' successfully unpacked and MD5 sums checked
    package 'rootSolve' successfully unpacked and MD5 sums checked
    package 'e1071' successfully unpacked and MD5 sums checked
    package 'lmom' successfully unpacked and MD5 sums checked
    package 'cellranger' successfully unpacked and MD5 sums checked
    package 'tibble' successfully unpacked and MD5 sums checked
    package 'cpp11' successfully unpacked and MD5 sums checked
    package 'progress' successfully unpacked and MD5 sums checked
    package 'curl' successfully unpacked and MD5 sums checked
    package 'jsonlite' successfully unpacked and MD5 sums checked
    package 'mime' successfully unpacked and MD5 sums checked
    package 'openssl' successfully unpacked and MD5 sums checked
    package 'R6' successfully unpacked and MD5 sums checked
    package 'TH.data' successfully unpacked and MD5 sums checked
    package 'sandwich' successfully unpacked and MD5 sums checked
    package 'mvtnorm' successfully unpacked and MD5 sums checked
    package 'expm' successfully unpacked and MD5 sums checked
    package 'rstudioapi' successfully unpacked and MD5 sums checked
    package 'Exact' successfully unpacked and MD5 sums checked
    package 'gld' successfully unpacked and MD5 sums checked
    package 'data.table' successfully unpacked and MD5 sums checked
    package 'readxl' successfully unpacked and MD5 sums checked
    package 'httr' successfully unpacked and MD5 sums checked
    package 'withr' successfully unpacked and MD5 sums checked
    package 'cli' successfully unpacked and MD5 sums checked
    package 'libcoin' successfully unpacked and MD5 sums checked
    package 'matrixStats' successfully unpacked and MD5 sums checked
    package 'modeltools' successfully unpacked and MD5 sums checked
    package 'multcomp' successfully unpacked and MD5 sums checked
    package 'zoo' successfully unpacked and MD5 sums checked
    package 'DescTools' successfully unpacked and MD5 sums checked
    package 'multcompView' successfully unpacked and MD5 sums checked
    package 'plyr' successfully unpacked and MD5 sums checked
    package 'coin' successfully unpacked and MD5 sums checked
    package 'lmtest' successfully unpacked and MD5 sums checked
    package 'nortest' successfully unpacked and MD5 sums checked
    package 'rcompanion' successfully unpacked and MD5 sums checked
    
    The downloaded binary packages are in
        C:\Users\bigar\AppData\Local\Temp\RtmpqOtrZ8\downloaded_packages