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

[ERROR] R Call errored, is R available ? #81

Closed NeilChangYanpeng closed 3 years ago

NeilChangYanpeng commented 3 years ago

Hi, it is my first time to use cdt, after installed by: pip install cdt

I ran: from cdt.causality.graph import GES obj=GES()

then I got this error: 图片

I'm working with cdt 0.5.21 , python 3.6.12 and torch 1.4.0, no GPU. Thank you for your help!

diviyank commented 3 years ago

Hello, Have you installed R on your device ? Otherwise, using the docker images would be a good alternative ! Best, Diviyan

NeilChangYanpeng commented 3 years ago

Hello, Have you installed R on your device ? Otherwise, using the docker images would be a good alternative ! Best, Diviyan

Thank you for your help, I installed R 4.0.3, but there are new errors when installing packages, some of the R packages are not available, you can see in the screenshot below: 图片 Since I have never used docker,could you please share with me more details to use docker images to solve this problem, or share with me a tutorial website.Thank you so much!

diviyank commented 3 years ago

Ok then R is installed, no problem on that part.

D2C is not used in the code, so it shouldn't pose any kind of problem for now. The issue might arise from the Rpath given to python. I think you need to specify cdt.SETTINGS.rpath to your path installation

example

import cdt

cdt.SETTINGS.rpath = 'C:/ProgramFiles/R/R' # path to your r executable
diviyank commented 3 years ago

What path did you provide for cdt.SETTINGS.rpath ?

NeilChangYanpeng commented 3 years ago

图片

diviyank commented 3 years ago

I think you need to add 'Rscript' : That makes:

cdt.SETTINGS.rpath = 'D:\Program Files\R\R-4.0.3\bin\Rscript'

The discussion at #70 might be useful for you

Best, Diviyan

NeilChangYanpeng commented 3 years ago

Thank you sooooooo much, @Diviyan-Kalainathan . It works by configuring rpath. 图片

diviyank commented 3 years ago

Great! I'll close this issue

merajso commented 2 years ago

Hello, Have you installed R on your device ? Otherwise, using the docker images would be a good alternative ! Best, Diviyan

Hi, I have the same problem. I installed R on my computer and set the cdt.SETTINGS.rpath. but still got the same error: "R Call errored, is R available ?" R Call errored, is R available ?

FileNotFoundError Traceback (most recent call last)

in ----> 1 model_pc = cdt.causality.graph.PC(CItest='gaussian', method_indep='corr', alpha=0.01, njobs=None, verbose=None) 2 # graph_pc = model_pc.predict(df) 3 graph_pc = model_pc.predict(df, skeleton) 4 5 # visualize network ~\Anaconda3\lib\site-packages\cdt\causality\graph\PC.py in __init__(self, CItest, method_indep, alpha, njobs, verbose) 173 njobs=None, verbose=None): 174 """Init the model and its available arguments.""" --> 175 if not (RPackages.pcalg and RPackages.kpcalg and RPackages.RCIT): 176 raise ImportError("R Package (k)pcalg/RCIT is not available. " 177 "RCIT has to be installed from " ~\Anaconda3\lib\site-packages\cdt\utils\R.py in __getattribute__(self, name) 130 out = object.__getattribute__(self, name) 131 if out is None and not object.__getattribute__(self, 'init'): --> 132 availability = self.check_R_package(name) 133 setattr(self, name, availability) 134 return availability ~\Anaconda3\lib\site-packages\cdt\utils\R.py in check_R_package(self, package) 144 bool: `True` if the package is available, `False` otherwise 145 """ --> 146 test_package = not bool(launch_R_script(Path("{}/R_templates/test_import.R".format(os.path.dirname(os.path.realpath(__file__)))), 147 {"{package}": package}, verbose=True)) 148 return test_package ~\Anaconda3\lib\site-packages\cdt\utils\R.py in launch_R_script(template, arguments, output_function, verbose, debug) 195 except Exception as e: 196 print("R Call errored, is R available ?") --> 197 raise e 198 199 else: ~\Anaconda3\lib\site-packages\cdt\utils\R.py in launch_R_script(template, arguments, output_function, verbose, debug) 190 if output_function is None: 191 try: --> 192 output = subprocess.call([str(rpath), "--vanilla", str(scriptpath)], 193 stdout=subprocess.DEVNULL, 194 stderr=subprocess.DEVNULL) ~\Anaconda3\lib\subprocess.py in call(timeout, *popenargs, **kwargs) 338 retcode = call(["ls", "-l"]) 339 """ --> 340 with Popen(*popenargs, **kwargs) as p: 341 try: 342 return p.wait(timeout=timeout) ~\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text) 856 encoding=encoding, errors=errors) 857 --> 858 self._execute_child(args, executable, preexec_fn, close_fds, 859 pass_fds, cwd, env, 860 startupinfo, creationflags, shell, ~\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session) 1309 # Start the process 1310 try: -> 1311 hp, ht, pid, tid = _winapi.CreateProcess(executable, args, 1312 # no special security 1313 None, None, FileNotFoundError: [WinError 2] The system cannot find the file specified
FTamas77 commented 1 year ago

Hi, I had the same problem. Adding this: cdt.SETTINGS.rpath = 'C:/Program Files/R/R-4.2.2' (without the binary) was a kind of half solution. Now, I face another problem.