Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (EternallyCurious, howardR), 646 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 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,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

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