Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by M_D. 04/26/24 20:22
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 839 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 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: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
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