FenTechSolutions / CausalDiscoveryToolbox

Package for causal inference in graphs and in the pairwise settings. Tools for graph structure recovery and dependencies are included.
https://fentechsolutions.github.io/CausalDiscoveryToolbox/html/index.html
MIT License
1.08k stars 198 forks source link

R Package (k)pcalg/RCIT is not available. RCIT has to be installed from #64

Closed c00h00g closed 1 year ago

c00h00g commented 4 years ago

`import cdt import networkx as nx import pandas as pd import matplotlib.pyplot as plt from cdt.causality.graph import PC

data = pd.read_csv('http://www.causality.inf.ethz.ch/data/lucas0_train.csv')

pc_output = PC().create_graph_from_data(data) nx.draw_networkx(pc_output) plt.show() `

when I run this code, I found this error, Traceback (most recent call last): File "test_cdt.py", line 13, in pc_output = PC().create_graph_from_data(data) File "/usr/local/lib/python3.7/site-packages/cdt/causality/graph/PC.py", line 175, 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

I've already install RCIT in R, need your help image

diviyank commented 4 years ago

Hello,

Okay, it seems that the process isn't seeing the RCIT package.. Did you install it from my fork or with install_packages ? My fork has some fittings done to be working with cdt. Install packages won't do ; anyway it doesn't seem to be the issue here. Can you write a small r-file like this:

# test.R 
library('RCIT')

and launch it with R-script :

Rscript test.R 

And tell me if that errors ?

c00h00g commented 4 years ago

Hello,

Okay, it seems that the process isn't seeing the RCIT package.. Did you install it from my fork or with install_packages ? My fork has some fittings done to be working with cdt. Install packages won't do ; anyway it doesn't seem to be the issue here. Can you write a small r-file like this:

# test.R 
library('RCIT')

and launch it with R-script :

Rscript test.R 

And tell me if that errors ?

I reinstall RCIT with your fork image

but, I still get the error below image

The result of test.R is image

diviyank commented 4 years ago

Have you installed pcalg and kpcalg ?

c00h00g commented 4 years ago

Have you installed pcalg and kpcalg ?

thx, after I installed pcalg and kpcalg, problem solved.

diviyank commented 4 years ago

Great, I'll close the issue.

rmansillal commented 3 years ago

Hello!, I have the same error: "ImportError: R Package pcalg is not available."

I have installed pcalg with pip, but the same doesn't work when I try to install kpcalg. How can I install kpcalg in python?

I will appreciate the help very much.

Thanks

diviyank commented 3 years ago

Hello ! The (k)pcalg dependencies are R-dependencies and not python dependencies, thus not installable with pip but rather with:

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

Best, Diviyan

rmansillal commented 3 years ago

Thanks very much!

Kind regards.

El mar, 2 feb 2021 a las 15:36, Diviyan Kalainathan (< notifications@github.com>) escribió:

Hello ! The (k)pcalg dependencies are R-dependencies and not python dependencies, thus not installable with pip but rather with:

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

Best, Diviyan

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/FenTechSolutions/CausalDiscoveryToolbox/issues/64#issuecomment-771721828, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKKVLTVCD2LTSCK74INKG3LS5ALZLANCNFSM4M3CAKQA .

-- Roberto Mansilla. PhD Student MSc Business Analytics Ingeniero Civil Industrial

Jaise152 commented 2 years ago

image Hi, I installed all the packages mentioned, but I am still getting same error. I am executing this on google colab.

NandaKishoreJoshi commented 2 years ago

I'm also facing the same issue as @Jaise152 after installing all the packages on databricks..

diviyank commented 2 years ago

Three packages are tested when trying to import cdt.causality.graph.PC :

        if not (RPackages.pcalg and RPackages.kpcalg and RPackages.RCIT):
            raise ImportError("R Package (k)pcalg/RCIT is not available. "
                              "RCIT has to be installed from "
                              "https://github.com/Diviyan-Kalainathan/RCIT")

So the error is not raising if the detected R installation (modifiable with cdt.SETTINGS.rpath) includes these packages

Could you check which R installation is detected ?

Best, Diviyan

NandaKishoreJoshi commented 2 years ago

Three packages are tested when trying to import cdt.causality.graph.PC :

        if not (RPackages.pcalg and RPackages.kpcalg and RPackages.RCIT):
            raise ImportError("R Package (k)pcalg/RCIT is not available. "
                              "RCIT has to be installed from "
                              "https://github.com/Diviyan-Kalainathan/RCIT")

So the error is not raising if the detected R installation (modifiable with cdt.SETTINGS.rpath) includes these packages

Could you check which R installation is detected ?

Best, Diviyan

Hi Diviyan, I trying to run this package on Databricks. So I'm not able to find where these r packages are being installed and maybe that's the reason why they are not getting detected. I'll reach out to databricks team to clear the path issue and update you

NandaKishoreJoshi commented 2 years ago
https://github.com/Diviyan-Kalainathan/RCIT

Hi Diviyan, Can you ping me the path from where this error is getting generated (the image you have shown) . It can help me to understand what Rpackages is..

diviyank commented 2 years ago

Hello, The line raising this error is here : https://github.com/FenTechSolutions/CausalDiscoveryToolbox/blob/master/cdt/causality/graph/PC.py#L175

Best, Diviyan

NandaKishoreJoshi commented 2 years ago

Hi Diviyan, Is there any particular order to install these packages? Or the below order should be fine Step 1: %r library(devtools) install_github("ericstrobl/RCIT") library(RCIT) RCIT(rnorm(1000),rnorm(1000),rnorm(1000)) RCoT(rnorm(1000),rnorm(1000),rnorm(1000)) RCoT(rnorm(1000),rnorm(1000),matrix(rnorm(2000),1000,2))

Step 2: %r install.packages("BiocManager") BiocManager::install(c("CAM", "SID", "bnlearn", "pcalg", "kpcalg", "D2C"))

NandaKishoreJoshi commented 2 years ago

I'm able to run the code now after installing all the dependent R packages and creating it as a init script on the databricks cluster. Below is the packages I installed (init script) manually by finding the tar files.

%python dbutils.fs.put("/databricks/test-scripts/install_Rpacakge.sh","""

!/bin/bash

Init Script to install CAM, SID, Bnlearn, pcalg, kpcalg and D2C R pacakages

sudo apt-get update -y sudo apt-get install -y libgsl-dev

pcalg and its dependencies

R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/abind_1_4_3_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/BiocGenerics_0_40_0_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/graph_1_72_0_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/BH_1_78_0_0_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/RBGL_1_70_0_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/igraph_1_2_10_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/ggm_2_5_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/corpcor_1_6_10_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/DEoptimR_1_0_9_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/robustbase_0_93_9_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/zoo_1_8_9_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/lmtest_0_9_39_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/vcd_1_4_9_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/bdsmatrix_1_3_4_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/sfsmisc_1_1_11_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/fastICA_1_2_3_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/clue_0_3_60_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/RcppArmadillo_0_10_7_5_0_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/pcalg_2_7_4_tar.gz

energy and its dependencies

R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/gsl_2_1_7_1_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/energy_1_7_8_tar.gz

kernlab and its dependencies

R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/kernlab_0_9_29_tar.gz

rspectra and its dependencies

R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/RcppEigen_0_3_3_9_1_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/RSpectra_0_16_0_tar.gz

kpcalg and its dependencies

R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/kpcalg_1_0_1_tar.gz

D2C and its dependencies

R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/irlba_2_3_5_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/gRbase_1_8_3_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/lazy_1_2_16_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/Rgraphviz_2_38_0_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/D2C_1_2_1_tar.gz

CAM and its dependencies

R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/stabs_0_6_4_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/nnls_1_4_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/quadprog_1_5_8_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/mvtnorm_1_1_3_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/libcoin_1_0_9_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/Formula_1_2_4_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/inum_1_0_4_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/partykit_1_2_15_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/mboost_2_9_5_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/CAM_1_0_tar.gz

SID

R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/SID_1_0_tar.gz

bnlearn

R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/bnlearn_4_7_tar.gz

RCIT and its dependencies

R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/MASS_7_3_54_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/momentchi2_0_1_5_tar.gz R CMD INSTALL --no-lock /dbfs/FileStore/tables/t/RCIT_0_1_0_tar.gz """, True)

csymvoul commented 1 year ago

Hello! How can I install pcalg and kpcalg? Whenever I try to install these packages (either using install.packages or BiocManager") I get the following error:

When trying to download it using install.packages("pcalg"):

ERROR: dependency ‘fastICA’ is not available for package ‘pcalg’
* removing ‘/home/csymvoul/R/x86_64-pc-linux-gnu-library/3.6/pcalg’
Warning in install.packages :
  installation of package ‘pcalg’ had non-zero exit status

And when I try to download fastICA it states that it is not an available package.

> install.packages("fastICA")
Installing package into ‘/home/csymvoul/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
Warning in install.packages :
  package ‘fastICA’ is not available (for R version 3.6.3)

When trying to download it using the BiocManager::install('pcalg'):

getOption("repos")' replaces Bioconductor standard repositories, see '?repositories' for details

replacement repositories:
    CRAN: https://cloud.r-project.org

Bioconductor version 3.10 (BiocManager 1.30.18), R 3.6.3 (2020-02-29)
Installing package(s) 'pcalg'
Warning: dependency ‘fastICA’ is not available
trying URL 'https://cloud.r-project.org/src/contrib/pcalg_2.7-6.tar.gz'
Content type 'application/x-gzip' length 4154653 bytes (4.0 MB)
==================================================
downloaded 4.0 MB

ERROR: dependency ‘fastICA’ is not available for package ‘pcalg’
* removing ‘/home/csymvoul/R/x86_64-pc-linux-gnu-library/3.6/pcalg’

The downloaded source packages are in
    ‘/tmp/RtmpXmDE1W/downloaded_packages’
Installation paths not writeable, unable to update packages
  path: /usr/lib/R/library
  packages:
    boot, class, cluster, codetools, KernSmooth, lattice, MASS, Matrix, mgcv, nlme, nnet, rpart, spatial, survival
Warning message:
In install.packages(...) :
  installation of package ‘pcalg’ had non-zero exit status
diviyank commented 1 year ago

Hello ! Damn these packages are not maintained anymore. I think the best way to solve these issues is to download/install all packages from CRAN. I will make a new script to install them.

Best, Diviyan

csymvoul commented 1 year ago

Thanks a lot @Diviyan-Kalainathan! Waiting for your script! If possible specify with R version you are using. I tried with both 3.6 and 4.2.1 and I get different errors each time.

diviyank commented 1 year ago

Hello again ! Can you try this ?

First using sudo, some packages needed :

apt-get install build-essential  -y --allow-unauthenticated
apt-get install libv8-dev  -y --allow-unauthenticated
apt-get  install libcurl4-openssl-dev -y --allow-unauthenticated
apt-get install libgsl-dev -y
apt-get install libxml2-dev -y --allow-unauthenticated

Then install the R packages:

Rscript -e 'install.packages(c("V8"),repos="http://cran.us.r-project.org")'
Rscript -e 'install.packages(c("sfsmisc"),repos="http://cran.us.r-project.org")'
Rscript -e 'install.packages(c("clue"),repos="http://cran.us.r-project.org")'
Rscript -e 'install.packages("https://cran.r-project.org/src/contrib/Archive/randomForest/randomForest_4.6-14.tar.gz", repos=NULL, type="source")'
Rscript -e 'install.packages(c("lattice"),repos="http://cran.us.r-project.org")'
Rscript -e 'install.packages(c("devtools"),repos="http://cran.us.r-project.org")'
Rscript -e 'install.packages(c("MASS"),repos="http://cran.us.r-project.org")'
Rscript -e 'install.packages("BiocManager")'
Rscript -e 'BiocManager::install(c("igraph"))'
Rscript -e 'install.packages("https://cran.r-project.org/src/contrib/Archive/fastICA/fastICA_1.2-2.tar.gz", repos=NULL, type="source")'
Rscript -e 'BiocManager::install(c("SID", "bnlearn", "pcalg", "kpcalg", "glmnet", "mboost"))'
Rscript -e 'install.packages("https://cran.r-project.org/src/contrib/Archive/CAM/CAM_1.0.tar.gz", repos=NULL, type="source")'
Rscript -e 'install.packages("https://cran.r-project.org/src/contrib/sparsebnUtils_0.0.8.tar.gz", repos=NULL, type="source")'
Rscript -e 'BiocManager::install(c("ccdrAlgorithm", "discretecdAlgorithm"))'

Rscript -e 'install.packages("devtools")'
Rscript -e 'library(devtools); install_github("cran/CAM"); install_github("cran/momentchi2"); install_github("Diviyan-Kalainathan/RCIT")'
Rscript -e 'install.packages("https://cran.r-project.org/src/contrib/Archive/sparsebn/sparsebn_0.1.2.tar.gz", repos=NULL, type="source")'
csymvoul commented 1 year ago

Can you please let me know of the R version you are using? Because now (using the R version 4.2.1 I get an error about a font library that is not supported...

diviyank commented 1 year ago

Hello, i'm using 3.6.3 without much issues, could you show your error message ?

diviyank commented 1 year ago

Hello, I updated the docker installation scripts for debian and ubuntu distributions, for R 4.2.1 (I also had the font issues that needed an apt install), 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 !

@csymvoul I will be closing this issue, don't hesitate to open a new one if the issue persists

Hope this helps, Best regards, Diviyan

LeoHink commented 1 year ago

Hi Diviyan,

I'm having issues accessing the package in python when I run my script in a Jupyter notebook. I get the following error message:

ImportError: R Package (k)pcalg/RCIT is not available. RCIT has to be installed from https://github.com/Diviyan-Kalainathan/RCIT

I have however installed RCIT in the environment that I'm also running my Jupyter notebook in. So I'm not sure why it can't access it. Any help would be appreciated.

Thanks, Leo

Mishu791 commented 1 year ago

Hello @Diviyan-Kalainathan

image

I installed all the R packages needed, but after that, I am having issues with igraph package! I tried reinstalling (igraph package version==igraph_1.3.5) but it did not work. and after clicking on 'ok' the same error comes:

ImportError: R Package (k)pcalg/RCIT is not available. RCIT has to be installed from https://github.com/Diviyan-Kalainathan/RCIT (since igraph is one of the dependency for 'pcalg' and 'kpcalg') r version: '4.1.0' python version: 3.10.4 Any help would be appreciated. Thanks

Mishu

Mishu791 commented 1 year ago

Hello @Diviyan-Kalainathan

image

I installed all the R packages needed, but after that, I am having issues with igraph package! I tried reinstalling (igraph package version==igraph_1.3.5) but it did not work. and after clicking on 'ok' the same error comes:

ImportError: R Package (k)pcalg/RCIT is not available. RCIT has to be installed from https://github.com/Diviyan-Kalainathan/RCIT (since igraph is one of the dependency for 'pcalg' and 'kpcalg') r version: '4.1.0' python version: 3.10.4 Any help would be appreciated. Thanks

Mishu

Well, problem solved. igraph needs to be installed from conda -forge

CardosoJr commented 1 year ago

Hi everyone, I'm facing these issues. What would be the best way to install all R dependencies on google colab?

Mishu791 commented 1 year ago

Hello @CardosoJr This article might be helpful: https://medium.com/@smmishu/installing-cdt-causal-discovery-toolbox-in-windows-9209967c33c9

zhangcun-yan commented 1 year ago

Thankyou very much! the work is excellence!