Gamestudio Links
Zorro Links
Newest Posts
Zorro version 3.0 prerelease!
by jcl. 02/12/26 14:05
MarginCost discrepancy?
by jcl. 02/12/26 14:02
Hedge on FXCM, 4 or 5?
by qin. 02/11/26 14:12
CMC MT4 CFD vs FX Active - what's better?
by mayarik. 02/11/26 11:00
print a "still alive" log
by qin. 02/10/26 12:16
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
1 registered members (TipmyPip), 7,786 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
ApprenticeInMuc, PatrickH90, USER0328, Sfrdragon, mayarik
19198 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
R bridge and rev #468756
10/16/17 19:40
10/16/17 19:40
Joined: Jul 2016
Posts: 64
G
gtell Offline OP
Junior Member
gtell  Offline OP
Junior Member
G

Joined: Jul 2016
Posts: 64
Dear all,
dear JCL,

with Zorro 1.66 the following example works fine:

Code:
#include <default.c>
#include <r.h>

function main()
{
  Rstart("",2); // enable output 
  
  var vecIn[5],vecOut[5];
  int i;
  for(i=0; i<5; i++) 
    vecIn[i] = i;
  
  Rset("rin",vecIn,5); // set up a vector
  Rx("rout <- rin * 10"); // perform some arithmetics
  Rx("print(rout)",3); // print rout to the Zorro window 
  Rv("rout",vecOut,5); // read it back
   
   if(!Rrun()) 
     printf("Error - R session aborted!");
   else 
    for(i=0; i<5; i++) 
      printf("%.0f ",vecOut[i]);
}



however, if I slightly change to:

Code:
#include <default.c>
#include <r.h>

function main()
{
  Rstart("",2); // enable output 
  
  var vecIn[100],vecOut[100], vecRev[5];
  int i;
  for(i=0; i<100; i++) 
    vecIn[i] = i;
  
  Rset("rin",vecIn,100); // set up a vector
  Rx("rout <- rin * 10"); // perform some arithmetics
  Rx("print(rout)",3); // print rout to the Zorro window 
  Rv("rout",vecOut,100); // read it back
   
  vecRev = rev(vecOut,5);
	
   if(!Rrun()) 
     printf("Error - R session aborted!");
   else 
    for(i=0; i<5; i++) 
      printf("%.0f ",vecRev[i]);
}



it should print:

1000 990 980 970 960

instead it prints:

0 0 0 0 0

Is there anything I am missing?
Thanks.
Cheers.

Re: R bridge and rev [Re: gtell] #468761
10/17/17 08:29
10/17/17 08:29
Joined: Jul 2000
Posts: 28,072
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,072
Frankfurt
A "rev" call does not change an existing series, it returns a new reversed series.

The correct use:

vars vecRev = rev(vecOut,5);


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1