[Python] How can I get rpy2 to successfully install or access the tidyverse within Linux?

Discussão em 'Python' iniciado por Stack, Dezembro 18, 2024.

  1. Stack

    Stack Membro Participativo

    I am attempting to use the tidyverse within rpy2 (version 3.5.16) on my Linux Mint computer. I figure that there are two potential ways to accomplish this task: (1) Using the tidyverse installation that already works within the R console and RStudio, or (2) importing the tidyverse within rpy2. My preference is to use the first option so that I can apply the same set of packages for tasks within R and Rpy2.

    Option 1: Importing pre-existing tidyverse package

    I had used sudo apt install r-base r-cran-tidyverse to install the tidyverse within my computer. I believe this install worked correctly, as the following code does not raise any errors within my R console and RStudio:

    library(tidyverse)

    However, running the following Python code within a Jupyter notebook fails:

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


    Error message:

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

    Is there a way that I can point Rpy2 to my existing tidyverse installation?

    Option 2: Installing a new copy of the tidyverse using rpy2

    This option is also failing for me. I tried running the following Python script:

    import rpy2
    from rpy2.robjects.packages import importr
    # import R's "base" package
    base = importr('base')

    # import R's "utils" package
    utils = importr('utils')
    utils.install_packages('tidyverse')
    print("Done!")


    However, a few minutes into the installation process, this error message appeared:

    ERROR: dependencies ‘conflicted’, ‘ragg’, ‘reprex’ are not available for package ‘tidyverse’
    * removing ‘/home/myusername/miniforge3/envs/myenv/lib/R/library/tidyverse’


    I thought I could resolve this issue by installing the packages individually, but when I ran utils.install_packages('conflicted'), I then got the following message:

    ERROR: dependency ‘memoise’ is not available for package ‘conflicted’

    I could try to manually install memoise also, but I figure that that package, in turn, might depend on another missing package. Is there an easier way to automatically install these missing packages?

    Continue reading...

Compartilhe esta Página