R bridge and rev

Posted By: gtell

R bridge and rev - 10/16/17 19:40

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.
Posted By: jcl

Re: R bridge and rev - 10/17/17 08:29

A "rev" call does not change an existing series, it returns a new reversed series.

The correct use:

vars vecRev = rev(vecOut,5);
© 2024 lite-C Forums