Rcpp Version 0.12.12
Formula.h
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 //
3 // Formula.h: Rcpp R/C++ interface class library -- formula
4 //
5 // Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
6 //
7 // This file is part of Rcpp.
8 //
9 // Rcpp is free software: you can redistribute it and/or modify it
10 // under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // Rcpp is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21 
22 #ifndef Rcpp__Formula_h
23 #define Rcpp__Formula_h
24 
25 #include <RcppCommon.h>
26 #include <Rcpp/Language.h>
27 
28 namespace Rcpp{
29 
33  {
34  public:
35 
37 
38  Formula_Impl(){} ;
39 
40  Formula_Impl(SEXP x){
41  switch( TYPEOF( x ) ){
42  case LANGSXP:
43  if( ::Rf_inherits( x, "formula") ){
44  Storage::set__( x );
45  } else{
46  Storage::set__( internal::convert_using_rfunction( x, "as.formula") ) ;
47  }
48  break;
49  case EXPRSXP:
50  case VECSXP:
51  /* lists or expression, try the first one */
52  if( ::Rf_length(x) > 0 ){
53  SEXP y = VECTOR_ELT( x, 0 ) ;
54  if( ::Rf_inherits( y, "formula" ) ){
55  Storage::set__( y ) ;
56  } else{
57  SEXP z = internal::convert_using_rfunction( y, "as.formula") ;
58  Storage::set__( z ) ;
59  }
60  } else{
61  throw not_compatible( "cannot create formula from empty list or expression" ) ;
62  }
63  break;
64  default:
65  Storage::set__( internal::convert_using_rfunction( x, "as.formula") ) ;
66  }
67  }
68 
69  explicit Formula_Impl( const std::string& code ) {
70  Storage::set__( internal::convert_using_rfunction( ::Rf_mkString(code.c_str()), "as.formula") ) ;
71  }
72 
73  void update(SEXP){}
74 
75  } ;
76 
77  typedef Formula_Impl<PreserveStorage> Formula ;
78 
79 } // namespace Rcpp
80 
81 #endif
Formula_Impl(SEXP x)
Definition: Formula.h:40
#define RCPP_GENERATE_CTOR_ASSIGN(__CLASS__)
Definition: interface.h:21
Formula_Impl< PreserveStorage > Formula
Definition: Formula.h:75
RCPP_API_CLASS(DottedPair_Impl)
Rcpp API.
Definition: algo.h:28
SEXP convert_using_rfunction(SEXP x, const char *const fun)
Definition: r_cast.h:30
void update(SEXP)
Definition: Environment.h:400