Logo ROOT  
Reference Guide
Proxy.C
Go to the documentation of this file.
1 #include<TRInterface.h>
2 #include<vector>
3 //script to test RExport a TRobjectProxy
4 void Proxy()
5 {
8  //////////////////////////
9  //Getting values from R //
10  //////////////////////////
11  std::cout << "======Getting values from R ======\n";
12  TString s = gR->ParseEval("'ROOTR'");
13 
14  TVectorD v = gR->ParseEval("c(1,2,3,4)");
15  std::vector<Double_t> sv=gR->ParseEval("c(1.01,2,3,4)");
16  TMatrixD m = gR->ParseEval("matrix(c(1,2,3,4),2,2)");
17 
18  std::cout<<"-----------------------------------"<<endl;
19  std::cout << s << std::endl;
20  std::cout<<"-----------------------------------"<<endl;
21  v.Print();
22  std::cout<<"-----------------------------------"<<endl;
23  for(int i=0;i<sv.size();i++) std::cout<<sv[i]<<" "<<std::endl;
24  std::cout<<"-----------------------------------"<<endl;
25  m.Print();
26 
27  Double_t d = gR->ParseEval("1.1");
28  Float_t f = gR->ParseEval("0.1");
29  Int_t i = gR->ParseEval("1");
30 
31  std::cout << d << " " << f << " " << i << std::endl;
32 
33  ////////////////////////
34  //Passing values to R //
35  /////////////////////////
36 
37  std::cout << "======Passing values to R ======\n";
38  gR->Assign(s, "s");
39  gR->Parse("print(s)");
40  std::cout<<"-----------------------------------"<<endl;
41 
42  (*gR)["v"]=v;
43  gR->Parse("print(v)");
44  std::cout<<"-----------------------------------"<<endl;
45 
46  gR->Assign(sv, "sv");
47  gR->Parse("print(sv)");
48  std::cout<<"-----------------------------------"<<endl;
49 
50  gR->Assign(m, "m");
51  gR->Parse("print(m)");
52  std::cout<<"-----------------------------------"<<endl;
53 
54  gR->Assign(d, "d");
55  gR->Parse("print(d)");
56  std::cout<<"-----------------------------------"<<endl;
57 
58  gR->Assign(f, "f");
59  gR->Parse("print(f)");
60  std::cout<<"-----------------------------------"<<endl;
61 
62  gR->Assign(i, "i");
63  gR->Parse("print(i)");
64 
65 }
m
auto * m
Definition: textangle.C:8
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
f
#define f(i)
Definition: RSha256.hxx:104
gR
static ROOT::R::TRInterface * gR
Definition: TRInterface.cxx:28
ROOT::R::TRInterface
ROOT R was implemented using the R Project library and the modules Rcpp and RInside
Definition: TRInterface.h:137
Float_t
float Float_t
Definition: RtypesCore.h:57
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
Int_t
int Int_t
Definition: RtypesCore.h:45
TString
Basic string class.
Definition: TString.h:136
TMatrixT< Double_t >
v
@ v
Definition: rootcling_impl.cxx:3635
TRInterface.h
ROOT::R::TRInterface::SetVerbose
void SetVerbose(Bool_t status)
Method to set verbose mode, that produce extra output.
Definition: TRInterface.cxx:132
ROOT::R::TRInterface::Assign
void Assign(const T &var, const TString &name)
Template method to assign C++ variables into R enviroment.
Definition: TRInterface.h:255
TVectorT< Double_t >
Double_t
double Double_t
Definition: RtypesCore.h:59
d
#define d(i)
Definition: RSha256.hxx:102
ROOT::R::TRInterface::InstancePtr
static TRInterface * InstancePtr()
static method to get an TRInterface instance pointer
Definition: TRInterface.cxx:173
Proxy
void Proxy()
Definition: Proxy.C:4