Logo ROOT   6.21/01
Reference Guide
Functions.C
Go to the documentation of this file.
1 //script to test TRFunction
2 #include<TRInterface.h>
3 #include<TMath.h>
4 double funv(TVectorD v)
5 {
6  return v[0] * v[1];
7 }
8 
9 void funm(TMatrixD m)
10 {
11  m.Print();
12 }
13 
14 void funs(TString s)
15 {
16  std::cout << "hello " << s.Data() << std::endl;
17 }
18 
19 //this prototype dont work because argument should be
20 //an object to pass an array.
22 {
23  return x[0] * par[0];
24 }
25 
27 {
28  return x * 3;;
29 }
30 
31 
32 void Functions(TString type = "Import")
33 {
36  if (type == "Export") {
37  std::cout << "-----------------------" << std::endl;
38  std::cout << "Testing FunctionExport" << std::endl;
39  std::cout << "-----------------------" << std::endl;
40  r["funv"] << ROOT::R::TRFunctionExport(funv);
41  r << "print(funv(c(2,3)))";
42 
43  r["funm"] << ROOT::R::TRFunctionExport(funm);
44  r << "cat(funm(matrix(c(1,2,3,4),2,2)))";
45 
46  r["funs"] << ROOT::R::TRFunctionExport(funs);
47 
48  r << "cat(funs('ROOTR'))";
49 
51  r << "print(DiLog(2))";
52 
53  r << "x <- seq(0,10,0.01)";
54  r << "y <- NULL ";
55  r << "for(i in seq(along=x)) { \
56  y <- c(y,DiLog(i)) \
57  }";
58 
60  f4.SetFunction(fun4);
61  r["fun4"] << f4;
62  r << "print(fun4(1))";
63  } else {
64  std::cout << "-----------------------" << std::endl;
65  std::cout << "Testing FunctionImport " << std::endl;
66  std::cout << "-----------------------" << std::endl;
67  ROOT::R::TRFunctionImport print("print");
68  print("Hola");
69 
71  ROOT::R::TRFunctionImport require("require");
72  ROOT::R::TRFunctionImport plot("plot");
73  ROOT::R::TRFunctionImport devoff("dev.off");
74 //
76 // ROOT::R::TRFunctionImport options("options");
77  ROOT::R::TRFunctionImport x11("x11");
78  ROOT::R::TRFunctionImport read("read.csv");
79  ROOT::R::TRFunctionImport head("head");
80  ROOT::R::TRFunctionImport aslist("as.list");
81 
82  ROOT::R::TRFunctionImport options("options");
83  options(ROOT::R::Label["device"]="x11");
84 
85 
86  r<<"test <- function() x11";
88 
89 
91 
92 // dev();
93 
94 
95  options("device='x11'");
96 //
97  ROOT::R::TRObject vector=c(1,2,3,4);
98  TVectorF v=vector;
99  TVectorF v2=c(11,22,33,44);
100  print(v);
101  print(v2);
102  ROOT::R::TRDataFrame obj=read("training.csv");
103 
104 // ROOT::R::TRDataFrame df(obj.As<ROOT::R::TRDataFrame>());
105  print(head(Rcpp::wrap(obj)));
106  print(head(obj));
107  x11();
108  plot(sin,0,6,ROOT::R::Label["type"]="s");
109  x11();
110  plot(sin,0,6,ROOT::R::Label["type"]="l");
111  x11();
112  plot(sin,0,6,ROOT::R::Label["type"]="p");
113 
114 
115 
116 // devoff();
117 // print(vector);
118 
119 // require("C50");
120  }
121 }
auto * m
Definition: textangle.C:8
TVectorT.
Definition: TMatrixTBase.h:79
Definition: test.py:1
Basic string class.
Definition: TString.h:131
double funv(TVectorD v)
Definition: Functions.C:4
TMatrixT.
Definition: TMatrixDfwd.h:22
Double_t x[n]
Definition: legend1.C:17
Double_t fun3(Double_t *x, Double_t *par)
Definition: Functions.C:21
void funm(TMatrixD m)
Definition: Functions.C:9
void SetFunction(T fun)
function to assign function to export, template method that supports a lot of function&#39;s prototypes ...
static constexpr double s
double sin(double)
SEXP wrap(const TString &s)
Definition: RExports.h:67
Double_t DiLog(Double_t x)
Modified Struve functions of order 1.
Definition: TMath.cxx:110
This is a class to get ROOT&#39;s objects from R&#39;s objects
Definition: TRObject.h:71
ROOT::R::TRInterface & r
Definition: Object.C:4
This is a class to pass functions from ROOT to R
Double_t fun4(Double_t x)
Definition: Functions.C:26
const Rcpp::internal::NamedPlaceHolder & Label
void funs(TString s)
Definition: Functions.C:14
const Bool_t kFALSE
Definition: RtypesCore.h:88
double Double_t
Definition: RtypesCore.h:55
void SetVerbose(Bool_t status)
Method to set verbose mode, that produce extra output
int type
Definition: TGX11.cxx:120
static TRInterface & Instance()
static method to get an TRInterface instance reference
void Functions(TString type="Import")
Definition: Functions.C:32
#define c(i)
Definition: RSha256.hxx:101
This is a class to pass functions from ROOT to R
This is a class to create DataFrames from ROOT to R
Definition: TRDataFrame.h:177