Logo ROOT  
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
14namespace ROOT {
15 namespace R {
16 const Rcpp::internal::NamedPlaceHolder &Label(Rcpp::_);
17 }
18}
19
20namespace Rcpp {
21//TVectorT
22 template<> SEXP wrap(const TVectorT<Double_t> &v)
23 {
24 std::vector<Double_t> vec(v.GetMatrixArray(), v.GetMatrixArray() + v.GetNoElements());
25 return wrap(vec);
26 }
27
28 template<> TVectorT<Double_t> as(SEXP v)
29 {
30 std::vector<Double_t> vec =::Rcpp::as<std::vector<Double_t> >(v);
31 return TVectorT<Double_t>(vec.size(), vec.data());
32 }
33
34 template<> SEXP wrap(const TVectorT<Float_t> &v)
35 {
36 std::vector<Float_t> vec(v.GetMatrixArray(), v.GetMatrixArray() + v.GetNoElements());
37 return wrap(vec);
38 }
39
40 template<> TVectorT<Float_t> as(SEXP v)
41 {
42 std::vector<Float_t> vec =::Rcpp::as<std::vector<Float_t> >(v);
43 return TVectorT<Float_t>(vec.size(), vec.data());
44 }
45
46//TMatrixT
47 template<> SEXP wrap(const TMatrixT<Double_t> &m)
48 {
49 Int_t rows = m.GetNrows();
50 Int_t cols = m.GetNcols();
51 Double_t *data = new Double_t[rows * cols];
52 m.GetMatrix2Array(data, "F"); //ROOT has a bug here(Fixed)
53 NumericMatrix mat(rows, cols, data);
54 return wrap(mat);
55 }
56
57 template<> TMatrixT<Double_t> as(SEXP m)
58 {
59 NumericMatrix mat =::Rcpp::as<NumericMatrix>(m);
60 return TMatrixT<Double_t>(mat.rows(), mat.cols(), mat.begin(), "F");
61 }
62
63 template<> SEXP wrap(const TMatrixT<Float_t> &m)
64 {
65 Int_t rows = m.GetNrows();
66 Int_t cols = m.GetNcols();
67 Float_t *data = new Float_t[rows * cols];
68 m.GetMatrix2Array(data, "F"); //ROOT has a bug here(Fixed)
69 NumericMatrix mat(rows, cols, data);
70 return wrap(mat);
71 }
72
73 template<> TMatrixT<Float_t> as(SEXP m)
74 {
75 NumericMatrix mat =::Rcpp::as<NumericMatrix>(m);
76 std::vector<Float_t> dat = Rcpp::as<std::vector<Float_t>>(mat);
77 return TMatrixT<Float_t>(mat.rows(), mat.cols(), &dat[0], "F");
78 }
79
80//TRObject
81 template<> SEXP wrap(const ROOT::R::TRObject &obj)
82 {
83 return obj.fObj;
84 }
85
86 template<> ROOT::R::TRObject as(SEXP obj)
87 {
88 return ROOT::R::TRObject(obj);
89 }
90//TRDataFrame
91 template<> SEXP wrap(const ROOT::R::TRDataFrame &obj)
92 {
93 return obj.df;
94 }
95
96 template<> ROOT::R::TRDataFrame as(SEXP obj)
97 {
98 return ROOT::R::TRDataFrame(Rcpp::as<Rcpp::DataFrame>(obj));
99 }
100
101//TRFunctionImport
102 template<> SEXP wrap(const ROOT::R::TRFunctionImport &obj)
103 {
104 return *obj.f;
105 }
106
107 template<> ROOT::R::TRFunctionImport as(SEXP obj)
108 {
109 return ROOT::R::TRFunctionImport(Rcpp::as<Rcpp::Function>(obj));
110 }
111
112}
113namespace ROOT {
114 namespace R {
115 VARIABLE_IS_NOT_USED SEXP ModuleSymRef = NULL;
116 }
117}
#define R(a, b, c, d, e, f, g, h, i)
Definition: RSha256.hxx:110
int Int_t
Definition: RtypesCore.h:41
double Double_t
Definition: RtypesCore.h:55
float Float_t
Definition: RtypesCore.h:53
TRDataFrame(const T1 &t1)
#define _(A, B)
Definition: cfortran.h:108
This is a class to create DataFrames from ROOT to R.
Definition: TRDataFrame.h:176
Rcpp::DataFrame df
Definition: TRDataFrame.h:180
This is a class to pass functions from ROOT to R.
This is a class to get ROOT's objects from R's objects.
Definition: TRObject.h:70
Rcpp::RObject fObj
Definition: TRObject.h:73
const Rcpp::internal::NamedPlaceHolder & Label
VARIABLE_IS_NOT_USED SEXP ModuleSymRef
Definition: RExports.cxx:115
VSD Structures.
Definition: StringConv.hxx:21
This is a class to support deprecated method to pass function to R's Environment, based in Rcpp::Inte...
Definition: RExports.h:64
SEXP wrap(const TString &s)
Definition: RExports.h:67
TString as(SEXP s)
Definition: RExports.h:71
auto * m
Definition: textangle.C:8