Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, Quad, EternallyCurious, 1 invisible), 726 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 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,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

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