Logo ROOT  
Reference Guide
RExports.h
Go to the documentation of this file.
1// @(#)root/r:$Id$
2// Author: Omar Zapata Omar.Zapata@cern.ch 29/05/2013
3
4
5/*************************************************************************
6 * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12#ifndef ROOT_R_RExports
13#define ROOT_R_RExports
14
15
16
17//ROOT headers
18#include <Rtypes.h>
19
20#include <TString.h>
21
22#include <TVector.h>
23
24#include <TMatrixT.h>
25
26#include <TArrayD.h>
27
28#include <TArrayF.h>
29
30#include <TArrayI.h>
31
32//std headers
33#include<string>
34#include<vector>
35//support for std c++11 classes
36#include<array>
37
38//pragma to disable warnings on Rcpp which have
39//so many noise compiling
40#if defined(__GNUC__)
41#pragma GCC diagnostic push
42#pragma GCC diagnostic ignored "-Wunknown-pragmas"
43#pragma GCC diagnostic ignored "-Wshadow"
44#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
45#pragma GCC diagnostic ignored "-Wunused-parameter"
46#pragma GCC diagnostic ignored "-Woverloaded-virtual"
47#pragma GCC diagnostic ignored "-Wextra"
48#pragma GCC diagnostic ignored "-Wignored-qualifiers"
49// disable warning for macos
50#if defined(__APPLE__)
51#pragma GCC diagnostic ignored "-Wnonportable-include-path"
52//This to fix conflict of RVersion.h from ROOT and Rversion.h from R
53#if !defined(R_Version)
54#define R_Version(v,p,s) ((v * 65536) + (p * 256) + (s))
55#endif
56// RAW is defined in a MacOS system header
57// but is defined as macro in RInternals.h
58#if defined(RAW)
59#undef RAW
60#endif
61#endif
62#endif
63
64#include<RcppCommon.h>
65
66
67//Some useful typedefs
68typedef std::vector<TString> TVectorString;
69
70namespace ROOT {
71 namespace R {
72 class TRFunctionExport;
73 class TRFunctionImport;
74 class TRDataFrame;
75 class TRObject;
76 }
77}
78
79namespace Rcpp {
80
81//TString
82 template<> inline SEXP wrap(const TString &s)
83 {
84 return wrap(std::string(s.Data()));
85 }
86 template<> inline TString as(SEXP s)
87 {
88 return TString(::Rcpp::as<std::string>(s).c_str());
89 }
90
91//TVectorT
92 template<> SEXP wrap(const TVectorT<Double_t> &v);
93 template<> TVectorT<Double_t> as(SEXP v);
94
95 template<> SEXP wrap(const TVectorT<Float_t> &v);
96 template<> TVectorT<Float_t> as(SEXP v);
97
98//TMatrixT
99 template<> SEXP wrap(const TMatrixT<Double_t> &m);
100 template<> TMatrixT<Double_t> as(SEXP) ;
101 template<> SEXP wrap(const TMatrixT<Float_t> &m);
102 template<> TMatrixT<Float_t> as(SEXP) ;
103
104//TRDataFrame
105 template<> SEXP wrap(const ROOT::R::TRDataFrame &o);
106 template<> ROOT::R::TRDataFrame as(SEXP) ;
107
108//TRObject
109 template<> SEXP wrap(const ROOT::R::TRObject &o);
110 template<> ROOT::R::TRObject as(SEXP) ;
111
112//TRFunctionImport
113 template<> SEXP wrap(const ROOT::R::TRFunctionImport &o);
114 template<> ROOT::R::TRFunctionImport as(SEXP) ;
115
116 template<class T, size_t i> std::array<T, i> as(SEXP &obj)
117 {
118 std::vector<T> v = Rcpp::as<std::vector<T> >(obj);
119 std::array<T, i> a;
120 std::copy(v.begin(), v.end(), a.begin());
121 return a;
122 }
123
124 namespace traits {
125 template <typename T, size_t i>
126 class Exporter<std::array<T, i> > {
127 public:
128 Exporter(SEXP x)
129 {
130 t = Rcpp::as<T, i>(x);
131 }
132 std::array<T, i> get()
133 {
134 return t;
135 }
136 private:
137 std::array<T, i> t;
138 } ;
139 }
140}
141
142#include<Rcpp.h>//this headers should be called after templates definitions
143#undef HAVE_UINTPTR_T
144#include<RInside.h>
145
146#ifdef Free
147// see https://sft.its.cern.ch/jira/browse/ROOT-9258
148# undef Free
149#endif
150
151// restore warning level of before
152#if defined(__GNUC__)
153#pragma GCC diagnostic pop
154#endif
155
156namespace ROOT {
157 namespace R {
158 //reference to internal ROOTR's Module that call ROOT's classes in R
159 extern VARIABLE_IS_NOT_USED SEXP ModuleSymRef;
160 template<class T> class class_: public Rcpp::class_<T> {
161 public:
162 class_(const Char_t *name_, const Char_t *doc = 0) : Rcpp::class_<T>(name_, doc) {}
163 };
164
165 //________________________________________________________________________________________________________
166 template <class T>
167 void function(const Char_t *name_, T fun, const Char_t *docstring = 0)
168 {
169 //template function required to create modules using the macro ROOTR_MODULE
170 Rcpp::function(name_, fun, docstring);
171 }
172
173 extern const Rcpp::internal::NamedPlaceHolder &Label;
174 }
175}
176
177
178//macros redifined to be accord with the namespace
179#define ROOTR_MODULE RCPP_MODULE
180#define ROOTR_EXPOSED_CLASS RCPP_EXPOSED_CLASS
181
182//modified definiton to support ROOTR namespace
183#define ROOTR_EXPOSED_CLASS_INTERNAL(CLASS)\
184 namespace ROOT{ \
185 namespace R{ \
186 class CLASS; \
187 }} \
188 RCPP_EXPOSED_CLASS_NODECL(ROOT::R::CLASS)
189
190
191
192//modified macro for ROOTR global Module Object Symbol Reference ROOT::R::ModuleSymRef
193#define LOAD_ROOTR_MODULE(NAME) Rf_eval( Rf_lang2( ( ROOT::R::ModuleSymRef == NULL ? ROOT::R::ModuleSymRef = Rf_install("Module") : ROOT::R::ModuleSymRef ), _rcpp_module_boot_##NAME() ), R_GlobalEnv )
194#endif
std::vector< TString > TVectorString
Definition: RExports.h:68
char Char_t
Definition: RtypesCore.h:37
This is a class to create DataFrames from ROOT to R.
Definition: TRDataFrame.h:176
This is a class to pass functions from ROOT to R.
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
class_(const Char_t *name_, const Char_t *doc=0)
Definition: RExports.h:162
Basic string class.
Definition: TString.h:136
Double_t x[n]
Definition: legend1.C:17
double T(double x)
Definition: ChebyshevPol.h:34
const Rcpp::internal::NamedPlaceHolder & Label
VARIABLE_IS_NOT_USED SEXP ModuleSymRef
Definition: RExports.cxx:116
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:167
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
This is a class to support deprecated method to pass function to R's Environment, based in Rcpp::Inte...
Definition: RExports.h:79
SEXP wrap(const TString &s)
Definition: RExports.h:82
TString as(SEXP s)
Definition: RExports.h:86
static constexpr double s
auto * m
Definition: textangle.C:8
auto * a
Definition: textangle.C:12