Logo ROOT   6.12/07
Reference Guide
RExports.cxx
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 2013-2014, Omar Andres Zapata Mesa *
3  * All rights reserved. *
4  * *
5  * For the licensing terms see $ROOTSYS/LICENSE. *
6  * For the list of contributors see $ROOTSYS/README/CREDITS. *
7  *************************************************************************/
8 #include<RExports.h>
9 #include<TRFunctionExport.h>
10 #include<TRObject.h>
11 #include<TRDataFrame.h>
12 #include<Rcpp/Vector.h>
13 
14 Rcpp::internal::NamedPlaceHolder ROOT::R::Label;
15 
16 namespace Rcpp {
17 //TVectorT
18  template<> SEXP wrap(const TVectorT<Double_t> &v)
19  {
20  std::vector<Double_t> vec(v.GetMatrixArray(), v.GetMatrixArray() + v.GetNoElements());
21  return wrap(vec);
22  }
23 
24  template<> TVectorT<Double_t> as(SEXP v)
25  {
26  std::vector<Double_t> vec =::Rcpp::as<std::vector<Double_t> >(v);
27  return TVectorT<Double_t>(vec.size(), vec.data());
28  }
29 
30  template<> SEXP wrap(const TVectorT<Float_t> &v)
31  {
32  std::vector<Float_t> vec(v.GetMatrixArray(), v.GetMatrixArray() + v.GetNoElements());
33  return wrap(vec);
34  }
35 
36  template<> TVectorT<Float_t> as(SEXP v)
37  {
38  std::vector<Float_t> vec =::Rcpp::as<std::vector<Float_t> >(v);
39  return TVectorT<Float_t>(vec.size(), vec.data());
40  }
41 
42 //TMatrixT
43  template<> SEXP wrap(const TMatrixT<Double_t> &m)
44  {
45  Int_t rows = m.GetNrows();
46  Int_t cols = m.GetNcols();
47  Double_t *data = new Double_t[rows * cols];
48  m.GetMatrix2Array(data, "F"); //ROOT has a bug here(Fixed)
49  NumericMatrix mat(rows, cols, data);
50  return wrap(mat);
51  }
52 
53  template<> TMatrixT<Double_t> as(SEXP m)
54  {
55  NumericMatrix mat =::Rcpp::as<NumericMatrix>(m);
56  return TMatrixT<Double_t>(mat.rows(), mat.cols(), mat.begin(), "F");
57  }
58 
59  template<> SEXP wrap(const TMatrixT<Float_t> &m)
60  {
61  Int_t rows = m.GetNrows();
62  Int_t cols = m.GetNcols();
63  Float_t *data = new Float_t[rows * cols];
64  m.GetMatrix2Array(data, "F"); //ROOT has a bug here(Fixed)
65  NumericMatrix mat(rows, cols, data);
66  return wrap(mat);
67  }
68 
69  template<> TMatrixT<Float_t> as(SEXP m)
70  {
71  NumericMatrix mat =::Rcpp::as<NumericMatrix>(m);
72  std::vector<Float_t> dat = Rcpp::as<std::vector<Float_t>>(mat);
73  return TMatrixT<Float_t>(mat.rows(), mat.cols(), &dat[0], "F");
74  }
75 
76 //TRObject
77  template<> SEXP wrap(const ROOT::R::TRObject &obj)
78  {
79  return obj.fObj;
80  }
81 
82  template<> ROOT::R::TRObject as(SEXP obj)
83  {
84  return ROOT::R::TRObject(obj);
85  }
86 //TRDataFrame
87  template<> SEXP wrap(const ROOT::R::TRDataFrame &obj)
88  {
89  return obj.df;
90  }
91 
92  template<> ROOT::R::TRDataFrame as(SEXP obj)
93  {
94  return ROOT::R::TRDataFrame(Rcpp::as<Rcpp::DataFrame>(obj));
95  }
96 
97 //TRFunctionImport
98  template<> SEXP wrap(const ROOT::R::TRFunctionImport &obj)
99  {
100  return *obj.f;
101  }
102 
103  template<> ROOT::R::TRFunctionImport as(SEXP obj)
104  {
105  return ROOT::R::TRFunctionImport(Rcpp::as<Rcpp::Function>(obj));
106  }
107 
108 }
109 namespace ROOT {
110  namespace R {
111  VARIABLE_IS_NOT_USED SEXP ModuleSymRef = NULL;
112  }
113 }
auto * m
Definition: textangle.C:8
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
float Float_t
Definition: RtypesCore.h:53
Int_t GetNcols() const
Definition: TMatrixTBase.h:125
TString as(SEXP s)
Definition: RExports.h:71
int Int_t
Definition: RtypesCore.h:41
Rcpp::DataFrame df
Definition: TRDataFrame.h:181
Rcpp::RObject fObj
Definition: TRObject.h:74
VARIABLE_IS_NOT_USED SEXP ModuleSymRef
Definition: RExports.cxx:111
SEXP wrap(const TString &s)
Definition: RExports.h:67
Element * GetMatrixArray()
Definition: TVectorT.h:78
TRDataFrame(const T1 &t1)
This is a class to get ROOT&#39;s objects from R&#39;s objects
Definition: TRObject.h:71
This is a class to pass functions from ROOT to R.
SVector< double, 2 > v
Definition: Dict.h:5
virtual void GetMatrix2Array(Element *data, Option_t *option="") const
Copy matrix data to array .
Int_t GetNoElements() const
Definition: TVectorT.h:76
Int_t GetNrows() const
Definition: TMatrixTBase.h:122
double Double_t
Definition: RtypesCore.h:55
This is a class to support deprecated method to pass function to R&#39;s Environment, based in Rcpp::Inte...
Definition: RExports.h:64
Rcpp::internal::NamedPlaceHolder Label
Definition: RExports.cxx:14
constexpr Double_t R()
Definition: TMath.h:213
This is a class to create DataFrames from ROOT to R
Definition: TRDataFrame.h:177