CausalDiscoveryToolbox icon indicating copy to clipboard operation
CausalDiscoveryToolbox copied to clipboard

Problems installing required R packages

Open marianlonga opened this issue 2 years ago • 10 comments

Hi, I'm trying to run the code from your tutorial but I'm having trouble installing the required R packages for CDT. I've installed pcalg using Bioconductor and I've installed RCIT from the Diviyan-Kalainathan/RCIT github repo but when I try to use the PC and GES algorithms I get the following errors:

>>> import cdt
Detecting 4 CUDA device(s).
>>> import networkx as nx
>>> from cdt.data import load_dataset
>>> from cdt.causality.graph import PC
>>> from cdt.causality.graph import GES
>>> data, graph = load_dataset("sachs")
>>> cdt.SETTINGS.rpath = '/users/mlonga/anaconda3/envs/research/bin/Rscript'
>>> model = PC()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/users/mlonga/anaconda3/envs/research/lib/python3.8/site-packages/cdt/causality/graph/PC.py", line 176, in __init__
    raise ImportError("R Package (k)pcalg/RCIT is not available. "
ImportError: R Package (k)pcalg/RCIT is not available. RCIT has to be installed from https://github.com/Diviyan-Kalainathan/RCIT
>>> model = GES()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/users/mlonga/anaconda3/envs/research/lib/python3.8/site-packages/cdt/causality/graph/GES.py", line 110, in __init__
    raise ImportError("R Package pcalg is not available.")
ImportError: R Package pcalg is not available.

Do you know how can I install all the required R packages to be able to run the code? Thanks!

marianlonga avatar Mar 06 '22 16:03 marianlonga

Having the same issue

inwaves avatar Mar 08 '22 09:03 inwaves

Hello, Have you installed the packages on the same R installation that is called by CDT ? you can find an installation script for ubuntu here: https://github.com/FenTechSolutions/CausalDiscoveryToolbox/blob/master/install-deps/install-dependencies.sh (execute it with sudo)

Best, Diviyan

diviyank avatar Mar 08 '22 09:03 diviyank

Hi, thanks for the reply.

I checked the location of RScript and it's /users/mlonga/anaconda3/envs/research/bin/Rscript and the packages are in /users/mlonga/anaconda3/envs/research/lib/R/library so in my code I set cdt.SETTINGS.rpath = '/users/mlonga/anaconda3/envs/research/bin/Rscript', so I think that should be fine.

I found your installation script but I'm not allowed to use sudo, do you have any script that only uses conda or pip to install the packages without sudo?

I also tried running some of the code from the installation script but I got the following error:

$ Rscript -e 'source("http://bioconductor.org/biocLite.R"); biocLite(c("CAM", "SID", "bnlearn", "pcalg", "kpcalg", "D2C"))'
Error: With R version 3.5 or greater, install Bioconductor packages using BiocManager; see https://bioconductor.org/install

I'm using Bioconductor 3.13 so I modified the code as follows, but then I get a lot of warnings and most of the packages fail to be installed:

$ Rscript -e 'BiocManager::install(c("CAM", "SID", "bnlearn", "pcalg", "kpcalg", "D2C"))'

(... a lot of similar warnings ...)
../inst/include/Eigen/src/Core/MatrixBase.h:48:34:   required from 'class Eigen::MatrixBase<Eigen::Block<const Eigen::Transpose<const Eigen::Block<Eigen::Block<const Eigen::Matrix<double, -1, -1>, -1, -1, true>, -1, -1, false> >, -1, -1, false> >'
(... a lot of similar warnings ...)

Warning messages:
1: package(s) not installed when version(s) same as current; use `force = TRUE` to
  re-install: 'bnlearn' 'pcalg' 
2: In .inet_warning(msg) :
  packages ‘CAM’, ‘D2C’ are not available for Bioconductor version '3.14'

Versions of these packages for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages
3: In .inet_warning(msg) :
  installation of package ‘RcppEigen’ had non-zero exit status
4: In .inet_warning(msg) :
  installation of package ‘mgcv’ had non-zero exit status
5: In .inet_warning(msg) :
  installation of package ‘SID’ had non-zero exit status
6: In .inet_warning(msg) :
  installation of package ‘RSpectra’ had non-zero exit status
7: In .inet_warning(msg) :
  installation of package ‘kpcalg’ had non-zero exit status

Maybe there could be a problem with the different package versions, which version of Bioconductor and other packages did you use?

marianlonga avatar Mar 08 '22 10:03 marianlonga

Did you manage to solve this issue? If yes, please assist. Thanks.

shahdhardn avatar Mar 27 '22 12:03 shahdhardn

No I haven't unfortunately, I just ended up using the cdt docker image.

marianlonga avatar Mar 27 '22 14:03 marianlonga

Hello,

I encountered the same issue on Windows, it turns out that some of the R packages have been archived, and have to be downloaded in source file tar.gz and then installed with these source files in R.

For instance, with CAM, I found the archive on the CRAN page https://cran.r-project.org/src/contrib/Archive/CAM/. And then, I ran the command in R: install.packages("/CAM_1.0.tar.gz", repos = NULL, type = "source")

It didn't work right away as it did not install the dependencies (glmnet and mboost), which I had to install by hand. I did the same with SID and D2C (for one of them, I also had to do it for the dependency with Rgrapghviz).

Now it seems to work for me, hope that helps other people too.

aboisbunon avatar Aug 11 '22 14:08 aboisbunon

@aboisbunon you can try https://stackoverflow.com/questions/18655976/install-the-package-that-has-been-removed-from-the-cran-repository-easily some package can be found on install.package("xxxx", repos="https://mran.microsoft.com/snapshot/2018-01-01") some deps cannot be install using snapshot, should install them directly

lockmatrix avatar Aug 13 '22 07:08 lockmatrix

Hello, I updated the docker installation scripts for debian and ubuntu distributions, for R 4.2.1, please check here, it might give you commands to execute on your device :

Debian : https://github.com/FenTechSolutions/base-docker-images/blob/main/cdt-env.dockerfile Ubuntu : https://github.com/FenTechSolutions/base-docker-images/blob/main/nv-cdt-env.dockerfile

This executes without any issues on CircleCI !

Hope this helps, Best regards, Diviyan

diviyank avatar Aug 13 '22 09:08 diviyank

Hi,

I'm trying to run the code from your basic tutorial but I'm having trouble installing the required R packages for CDT on Google colab.

Below, there is an extract from my code (after pip install cdt, import cdt, import networkx as nx...)

 model = cdt.causality.graph.GES()

**ImportError: R Package pcalg is not available.**

-> Which code should I run in Colab to install the R packages?

Thank you,

Olivier

Olivier-FONTAINE avatar Oct 18 '23 12:10 Olivier-FONTAINE

Hello, I don't think that you"ll be able to run CDT on google Colab (at least for the R-based algorithms): the execution relies on having R and the respective packages installed.

The best way -currently- to run CDT is to pass through the docker image

Best, Diviyan

diviyank avatar Oct 19 '23 09:10 diviyank