Skip to content

Commit e9114ad

Browse files
committed
Merge branch 'RcppCore/master'
2 parents ca82a84 + 75c3f6d commit e9114ad

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

ChangeLog

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2016-07-22 James J Balamuta <balamut2@illinois.edu>
2+
* inst/include/Rcpp/Environment.h: Added get() & find() that accept
3+
a symbol
4+
* inst/include/Rcpp.h: Modified header load order so that Symbol.h
5+
is now placed before Environment.h
6+
17
2016-07-21 Dirk Eddelbuettel <edd@debian.org>
28

39
* DESCRIPTION (Version): Roll minor release
@@ -10,7 +16,7 @@
1016

1117
* DESCRIPTION: Release 0.12.6
1218
* inst/NEWS.Rd: Release 0.12.6
13-
* vignettes/Rcpp.bib: Release 0.12.6, RProtoBuf updates
19+
* vignettes/Rcpp.bib: Release 0.12.6, RProtoBuf updates
1420
* inst/include/Rcpp/config.h: Release 0.12.6
1521

1622
* README.md: Updated counts for dependents and tests

inst/NEWS.Rd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
\itemize{
1010
\item The \code{NORET} macro is now defined if it was not already defined
1111
by R (Kevin fixing issue \ghit{512}).
12+
\item Environment functions get() & find() now accept a Symbol
13+
(James Joseph Balamuta in \ghpr{513} addressing issue \ghit{326}).
1214
}
1315
}
1416
}

inst/include/Rcpp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include <Rcpp/clone.h>
3434
#include <Rcpp/grow.h>
3535
#include <Rcpp/Dimension.h>
36+
37+
#include <Rcpp/Symbol.h>
3638
#include <Rcpp/Environment.h>
3739

3840
#include <Rcpp/Vector.h>
@@ -42,7 +44,6 @@
4244
#include <Rcpp/Promise.h>
4345

4446
#include <Rcpp/XPtr.h>
45-
#include <Rcpp/Symbol.h>
4647
#include <Rcpp/DottedPairImpl.h>
4748
#include <Rcpp/Function.h>
4849
#include <Rcpp/Language.h>

inst/include/Rcpp/Environment.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,27 @@ namespace Rcpp{
115115
}
116116
return res ;
117117
}
118+
119+
/**
120+
* Get an object from the environment
121+
*
122+
* @param name symbol name to call
123+
*
124+
* @return a SEXP (possibly R_NilValue)
125+
*/
126+
SEXP get(Symbol name) const {
127+
SEXP env = Storage::get__() ;
128+
SEXP res = Rf_findVarInFrame( env, name ) ;
129+
130+
if( res == R_UnboundValue ) return R_NilValue ;
131+
132+
/* We need to evaluate if it is a promise */
133+
if( TYPEOF(res) == PROMSXP){
134+
res = Rf_eval( res, env ) ;
135+
}
136+
return res ;
137+
}
138+
118139

119140
/**
120141
* Get an object from the environment or one of its
@@ -136,6 +157,29 @@ namespace Rcpp{
136157
}
137158
return res ;
138159
}
160+
161+
/**
162+
* Get an object from the environment or one of its
163+
* parents
164+
*
165+
* @param name symbol name to call
166+
*/
167+
SEXP find(Symbol name) const{
168+
SEXP env = Storage::get__() ;
169+
SEXP res = Rf_findVar( name, env ) ;
170+
171+
if( res == R_UnboundValue ) {
172+
// Pass on the const char* to the RCPP_EXCEPTION_CLASS's
173+
// const std::string& requirement
174+
throw binding_not_found(name.c_str()) ;
175+
}
176+
177+
/* We need to evaluate if it is a promise */
178+
if( TYPEOF(res) == PROMSXP){
179+
res = Rf_eval( res, env ) ;
180+
}
181+
return res ;
182+
}
139183

140184
/**
141185
* Indicates if an object called name exists in the

0 commit comments

Comments
 (0)