Logo ROOT   6.18/05
Reference Guide
Binding.C
Go to the documentation of this file.
1// Author: Omar Zapata
2#include<TRInterface.h>
3#include<vector>
4#include<array>
5
7{
8 return x/(x-1);
9}
10
12{
13 return x/(x-1);
14}
15//overloaded function to test the operator <<
17{
18 return x-1;
19}
20
21void Binding(){
22//creating variables
23TVectorD v(3);
24std::vector<Double_t> sv(3);
25std::array<Int_t,3> a{ {1,2,3} };
26TString str("ROOTR");
27TMatrixD m(2,2);
28Int_t i=9;
29Double_t d=2.013;
30Float_t f=0.013;
31
32//assinging values
33v[0]=0.01;
34v[1]=1.01;
35v[2]=2.01;
36
37sv[0]=0.101;
38sv[1]=0.202;
39sv[2]=0.303;
40
41m[0][0]=0.01;
42m[0][1]=1.01;
43m[1][0]=2.01;
44m[1][1]=3.01;
45
47// r.SetVerbose(kTRUE);
48
49//testing operators binding
50r["a"]<<1;
51r["v"]<<v;
52r["sv"]<<sv;
53r["m"]<<m;
54r["b"]<<123.456;
55r["i"]<<i;
56r["d"]<<d;
57r["f"]<<f;
58r["array"]<<a;
59r["s"]<<"ROOT";
60
61
62//printting results
63std::cout<<"-----------Printing Results---------\n";
64r<<"print(a)";
65std::cout<<"--------------------\n";
66r<<"print(v)";
67std::cout<<"--------------------\n";
68r<<"print(sv)";
69std::cout<<"--------------------\n";
70r<<"print(m)";
71std::cout<<"--------------------\n";
72r<<"print(b)";
73std::cout<<"--------------------\n";
74r<<"print(i)";
75std::cout<<"--------------------\n";
76r<<"print(d)";
77std::cout<<"--------------------\n";
78r<<"print(f)";
79std::cout<<"--------------------\n";
80r<<"print(s)";
81std::cout<<"--------------------\n";
82r<<"print(array)";
83std::cout<<"--------------------\n";
84
85//reassigning the variable s
86r["s"]<<str;//string with string
87r<<"print(s)";
88
89// std::cout<<"--------------------\n";
90// r["d"]<<str;//double with string
91// r<<"print(d)";
92
94r<<"print(Function(-1))";
95
96r<<"print(Function(1))";//division by zero producess Inf.
97
98r<<"print('hello ')"<<std::string("print('world ')");
99r["x"]=123;
100r["y"]=321;
101
102Int_t x;
103x=r["x"];
104std::cout<<x<<std::endl;
105
106r["y"]>>x;
107std::cout<<x<<std::endl;
108
109r<<"mat<-matrix(c(1,2,3,4),nrow=2)";
110
111TMatrixD mat(2,2);
112r["mat"]>>mat;
113
114r["m"]<<mat;
115
116Double_t b;
117Int_t aa;
118TString str2;
119r["a"]>>aa;
120r["v"]>>v;
121r["sv"]>>sv;
122r["m"]>>m;
123r["b"]>>b;
124r["i"]>>i;
125r["d"]>>d;
126r["f"]>>f;
127r["array"]>>a;
128r["s"]>>str2;
129
130mat.Print();
131std::cout<<" array={"<<a[0]<<","<<a[1]<<","<<a[2]<<"}";
132r["func"]<<Function;
133r<<"print(func(2))";
134std::cout<<"func="<<Function(2);
135
136//passing overloaded functions
137r["funi"]<<(Int_t (*)(Int_t))Fun;
138r<<"print(funi(2))";
139std::cout<<"funi="<<Fun(2)<<std::endl;
140
141r["fund"]<<(Double_t (*)(Double_t))Fun;
142r<<"print(fund(2.01))";
143std::cout<<"fund="<<Fun(2.01)<<std::endl;
144
145//if you uncomment the next line you get a big
146//traceback because the template can not reslve the overloaded
147//function.
148//r["fun"]<<Fun;
149}
void Binding()
Definition: Binding.C:21
Double_t Function(Double_t x)
Definition: Binding.C:6
Double_t Fun(Double_t x)
Definition: Binding.C:11
SVector< double, 2 > v
Definition: Dict.h:5
ROOT::R::TRInterface & r
Definition: Object.C:4
#define d(i)
Definition: RSha256.hxx:102
#define b(i)
Definition: RSha256.hxx:100
#define f(i)
Definition: RSha256.hxx:104
int Int_t
Definition: RtypesCore.h:41
double Double_t
Definition: RtypesCore.h:55
float Float_t
Definition: RtypesCore.h:53
This is a class to pass functions from ROOT to R.
ROOT R was implemented using the R Project library and the modules Rcpp and RInside
Definition: TRInterface.h:137
static TRInterface & Instance()
static method to get an TRInterface instance reference
void Print(Option_t *name="") const
Print the matrix as a table of elements.
Basic string class.
Definition: TString.h:131
Double_t x[n]
Definition: legend1.C:17
auto * m
Definition: textangle.C:8
auto * a
Definition: textangle.C:12