2
$\begingroup$
process=StartProcess[$SystemShell];
outputFile=FileNameJoin[{NotebookDirectory[],"output.txt"}];
ClearAll[run];
run[commands_,seconds_:2]:=Module[{},
    commandSent=commands<>" > \""<>outputFile<>"\"";
    WriteLine[process,commandSent];
    Pause[seconds];
    Import[outputFile]
];

$rDirectory="C:\\Program Files\\R\\R-3.3.0\\bin\\x64";

now runnning

run["cd \""<>$rDirectory<>"\""]

and

run["dir"]

produces the same result as running on cmd directly but running

run["R.exe"]

doesn't seem to start the R process. But if i do these directly on cmd it works.

I have used this method several times to connect to external processes but it is not working for R. Someone please help!!!

$\endgroup$
14
  • $\begingroup$ Run is for single execution while i want to keep sending a sequence of commands programmatically and retrieve results. Can you please check whether i am the only one having this problem or there is some issue? $\endgroup$
    – user13892
    Sep 15, 2018 at 17:49
  • $\begingroup$ Oh sorry. Forget about what I said. I thought it was about a typo... $\endgroup$ Sep 15, 2018 at 17:51
  • 1
    $\begingroup$ But you might be interested in RLink... $\endgroup$ Sep 15, 2018 at 17:53
  • $\begingroup$ Stupid RLink crashes for large data. And has other bugs. I want the program to run in R but queries generated programmatically since there are alot of combinations. $\endgroup$
    – user13892
    Sep 15, 2018 at 17:55
  • $\begingroup$ Do i need to add it to "PATH" since i am cd-ing to the directory which has the executable? $\endgroup$
    – user13892
    Sep 15, 2018 at 17:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.