Running R from a zorro script.

Posted By: JackSturgeon

Running R from a zorro script. - 04/24/16 19:09

All,

I try to run Zorro 1.42 with the laters R 3.2.5 on windows 10.

To do this, I installed both programms and added the right path to the zorro.ini file.

RTermPath = "c:\Program Files\R\R-3.1.3\bin\i386\Rterm.exe"

When I run the RTest script in Zorro it fails.

Did anybody see this behavior? How can I fix this?

Thanks in advance.

Jack
Posted By: boatman

Re: Running R from a zorro script. - 04/25/16 04:54

Your RTermPath does not lead to R 3.2.5. Perhaps you have updated your R installation, but not your Zorro.ini file?
Posted By: JackSturgeon

Re: Running R from a zorro script. - 04/25/16 05:33

That is a correct observation.

I first installed the newest R and the newest Zorro. Then I tried to configure the R bridge with the RTermPath variable in the Zorro.ini file.

Because that did not work, I thought it might be the R version. Because Zorro.ini points to the older version I downloaded that and installed it. So I really have the older R release installed and I am pointing to it correctly.

Jack.
Posted By: JackSturgeon

Re: Running R from a zorro script. - 04/25/16 08:02

In addition to the previous...

I tried to install the newest zorro and R on another machine. I changed the line for RTermPath into the following:

RTermPath = "C:\Program Files\R\R-3.2.5\bin\i386\Rterm.exe"

It still does not work. Is there a way to get some logging out of the zorro process to see what happens?

Jacco.
Posted By: jcl

Re: Running R from a zorro script. - 04/25/16 12:56

R 3.2.5 works fine with Zorro. Here's a script that produces some diagnostics at start:

Code:
function main()
{
	if(!g->sRTermPath) {
		printf("R path missing! ");
		return;
	}
	if(!file_date(g->sRTermPath)) {
		printf("%s not found! ",g->sRTermPath);
		return;
	}
	string Cmd = strf("%s  --no-save",g->sRTermPath);
	printf(Cmd); 
	hR = RInit_(Cmd,2);
	if(!hR) {
		printf("Can't initialize RTerm! ");
		return;
	}
	Rx("rm(list = ls());"); // clear the workspace
	
	var vecIn[5],vecOut[5];
	int i;
	for(i=0; i<5; i++) 
		vecIn[i] = i;
	
	Rset("Rin",vecIn,5);
	Rx("Rout <- Rin * 10");
	Rv("Rout",vecOut,5);
	
	if(!Rrun()) 
		printf("Error - R session aborted!");
	else {
		printf("\nReturned: ");
		for(i=0; i<5; i++) 
			printf("%.0f ",vecOut[i]);
	}
}

Posted By: Sphin

Re: Running R from a zorro script. - 04/25/16 13:50

Windows sometimes goes strange ways. I often face problems with applications installed in "\Programm Files" because of special NTFS settings. I installed R directly in C:\\R\... and had no problems anymore.
Posted By: JackSturgeon

Re: Running R from a zorro script. - 04/25/16 15:00

All,

First of all, thanks for all the support. I think there is something wrong when zorro tries to run R with the command Rrun.

I slightly modified the print statements in the script above and I added the r.h include. It now looks like:
#include <r.h>

function main()
{
if(!g->sRTermPath) {
printf("R path missing! ");
return;
}
if(!file_date(g->sRTermPath)) {
printf("%s not found! ",g->sRTermPath);
return;
}
string Cmd = strf("Command : %s --no-save",g->sRTermPath);
printf(Cmd);
hR = RInit_(Cmd,2);
if(!hR) {
printf("Can't initialize RTerm! ");
return;
}

Rx("rm(list = ls());"); // clear the workspace

var vecIn[5],vecOut[5];
int i;
for(i=0; i<5; i++)
vecIn[i] = i;

Rset("Rin",vecIn,5);
Rx("Rout <- Rin * 10");
Rv("Rout",vecOut,5);

if(!Rrun())
printf("\nError - R session aborted!");
else {
printf("\nReturned: ");
for(i=0; i<5; i++)
printf("%.0f ",vecOut[i]);
}
}

The output is:
Zorro 1.42.2 Trading Automaton
Made with Gamestudio by oP group 2015

testREnv compiling.................
Command : C:\R\bin\x64\Rterm.exe --no-save
Error - R session aborted!

So the script aborts when running the Rrun() command.

Just to make sure, I now installed R in C:\R as shown in the output. My RTermPath is:

RTermPath = "C:\R\bin\x64\Rterm.exe"

Both the x64 and the i386 do not work.

Jacco.
Posted By: jcl

Re: Running R from a zorro script. - 04/25/16 15:31

Ok, so R was correctly initialized, but then terminated for some unknown reason. Can you replace the line

Rx("rm(list = ls());");

with

RExecute(hR,"rm(list = ls());");
printf("\n%s",RLastOutput(hR));
if(!RIsRunning(hR)) {
printf("\nR stopped!");
return;
} else
printf("\nR still running...");

and let me know what it prints?
Posted By: JackSturgeon

Re: Running R from a zorro script. - 04/26/16 07:50

Hi Chief, ;-)

I changed the script as you indecated and it prints the following:


testREnv compiling.................
Command : C:\R\bin\x64\Rterm.exe --no-save

R stopped!

I tried to run the complete command from a cmd and this start up Rterm.exe
perfectly. I get the prompt and can leave with q() as expected.

From the zorro script Rterm.exe seems to stop as printed by the zorro script.

I hope you have a suggestion of what to do.
Posted By: jcl

Re: Running R from a zorro script. - 04/26/16 08:59

Ok, now it becomes a little more complicated since you need to download a tool, the Debug Viewer. You can download it from many places, f.i. here:

https://technet.microsoft.com/en-us/sysinternals/debugview.aspx

Start it with default options. "Capture Win32" should be on. Now start the test script again and post here what the debug viewer prints out.
Posted By: jcl

Re: Running R from a zorro script. - 04/26/16 10:27

Before applying the debug viewer, here's something else to try. Please download this:

http://server.conitec.net/down/include.zip

It contains a new r.h include file. Please replace the old one with it and try again. Tell me how this works.
Posted By: JackSturgeon

Re: Running R from a zorro script. - 04/26/16 10:31

This is the output from debugview:

[9348] installed exception handler for C:\Program Files (x86)\Zorro\mt4R.DLL
[9348] <0> Create: Failed to execute C : 2
[9348] <0> Create: Error: R did not start: 2
[9348] RInit: RHandle = BD8E63C (198764092)
[9348] RDeinit: RHandle = BD8E63C (198764092)
[9348] <-1> TRConsole: destroying

Especially this line:

[9348] <0> Create: Failed to execute C : 2

seems interesting
Posted By: jcl

Re: Running R from a zorro script. - 04/26/16 10:36

Thanks! The "2" confirms my suspicion. Can you try with the new r.h?
Posted By: JackSturgeon

Re: Running R from a zorro script. - 04/26/16 11:51

How do I get the new r.h?

I only know the one in the include directory.
Posted By: jcl

Re: Running R from a zorro script. - 04/26/16 12:06

Look at my post above.
Posted By: JackSturgeon

Re: Running R from a zorro script. - 04/26/16 19:10

The new r.h did the trick.

It works now as expected.

Zorro 1.42.2 Trading Automaton
Made with Gamestudio by oP group 2015


RTest compiling.................
0 10 20 30 40

Thanks a lot. I can start digging around now. ;-)
Posted By: Grant

Re: Running R from a zorro script. - 04/10/20 15:39

Greetings,

I experience similar issues, while running Zorro 2.25 with R 3.6.2 on Wine. I can't run the RTest script properly:

Code
RTest compiling.............. ok
C:\Program Files\R\R-3.6.2\bin\x64\RTerm.exe  --no-save
R initialized!

R stopped!


Things, I've tried to far:
- Tried two types of RTermPath's in zorro.ini, "C:\Program Files\R\R-3.6.2\bin\x64\RTerm.exe" and "/home/administrator/.wine/drive_c/Program Files/R/R-3.6.2/bin/x64/RTerm.exe".
- Reinstalled both Zorro and R.

When I run DebugView while running the script, it returns:

Code
[38] <2> Create: trying to start R: C:\Program Files\R\R-3.6.2\bin\x64\RTerm.exe  --no-save
[38] <0> Create: Failed to execute C:\Program Files\R\R-3.6.2\bin\x64\RTerm.exe  --no-save : 5
[38] <0> Create: Error: R did not start: 5
[38] RInit: RHandle = 25A1904 (39459076)
[38] RDeinit: RHandle = 25A1904 (39459076)
[38] <-1> TRConsole: destroying


FYI, I'm able to run a RTerm instance manually.

Cheers,

Grant




Posted By: Smon

Re: Running R from a zorro script. - 04/10/20 17:53

Try R version 3.5.3

There have been compatibility problems with deep learning libraries with more recent functions half a year ago. I stopped hunting the newest R version since then.
Posted By: Grant

Re: Running R from a zorro script. - 04/13/20 14:55

Thank you for your suggestion, Smon. Unfortunately downgrading my R version resulted in the same problem.

I was able to run RTest successfully after installing Zorro and R in a Crossover environment. For whatever reason it's not possible to run the 64 bit version of Rterm.exe (tested in multiple 64 bit 'bottles' in Crossover), but the 32-bit version works fine.

BTW, a nice benefit of Crossover over Wine is that the visual appearance of Zorro is still fine after minimizing its window.

Grant
© 2024 lite-C Forums