|
Re: Running R from a zorro script.
[Re: JackSturgeon]
#459160
04/25/16 12:56
04/25/16 12:56
|
Joined: Jul 2000
Posts: 27,986 Frankfurt
jcl
Chief Engineer
|
Chief Engineer
Joined: Jul 2000
Posts: 27,986
Frankfurt
|
R 3.2.5 works fine with Zorro. Here's a script that produces some diagnostics at start:
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]);
}
}
|
|
|
Re: Running R from a zorro script.
[Re: Sphin]
#459168
04/25/16 15:00
04/25/16 15:00
|
Joined: Apr 2016
Posts: 10
JackSturgeon
OP
Newbie
|
OP
Newbie
Joined: Apr 2016
Posts: 10
|
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.
|
|
|
|