22// Environment.h: Rcpp R/C++ interface class library -- access R environments
33//
44// Copyright (C) 2009-2013 Dirk Eddelbuettel and Romain François
5- // Copyright (C) 2014-2026 Dirk Eddelbuettel, Romain François and Kevin Ushey
5+ // Copyright (C) 2014-2025 Dirk Eddelbuettel, Romain François and Kevin Ushey
6+ // Copyright (C) 2026 Dirk Eddelbuettel, Romain François, Kevin Ushey and Iñaki Ucar
67//
78// This file is part of Rcpp.
89//
@@ -95,20 +96,8 @@ namespace Rcpp{
9596 * @return a SEXP (possibly R_NilValue)
9697 */
9798 SEXP get (const std::string& name) const {
98- SEXP env = Storage::get__ () ;
99- SEXP nameSym = Rf_install (name.c_str ());
100- #if R_VERSION < R_Version(4,5,0)
101- SEXP res = Rf_findVarInFrame ( env, nameSym ) ;
102- #else
103- SEXP res = R_getVarEx (nameSym, env, FALSE , R_UnboundValue);
104- #endif
105- if ( res == R_UnboundValue ) return R_NilValue ;
106-
107- /* We need to evaluate if it is a promise */
108- if ( TYPEOF (res) == PROMSXP){
109- res = internal::Rcpp_eval_impl ( res, env ) ; // #nocov
110- }
111- return res ;
99+ Symbol nameSym = Rf_install (name.c_str ());
100+ return get (nameSym);
112101 }
113102
114103 /* *
@@ -122,16 +111,12 @@ namespace Rcpp{
122111 SEXP env = Storage::get__ () ;
123112#if R_VERSION < R_Version(4,5,0)
124113 SEXP res = Rf_findVarInFrame ( env, name ) ;
114+ if (res == R_UnboundValue) return R_NilValue;
115+ if (TYPEOF (res) == PROMSXP)
116+ res = internal::Rcpp_eval_impl (res, env);
125117#else
126- SEXP res = R_getVarEx (name, env, FALSE , R_UnboundValue );
118+ SEXP res = R_getVarEx (name, env, FALSE , R_NilValue );
127119#endif
128-
129- if ( res == R_UnboundValue ) return R_NilValue ;
130-
131- /* We need to evaluate if it is a promise */
132- if ( TYPEOF (res) == PROMSXP){
133- res = internal::Rcpp_eval_impl ( res, env ) ;
134- }
135120 return res ;
136121 }
137122
@@ -144,21 +129,8 @@ namespace Rcpp{
144129 *
145130 */
146131 SEXP find ( const std::string& name) const {
147- SEXP env = Storage::get__ () ;
148- SEXP nameSym = Rf_install (name.c_str ());
149- #if R_VERSION < R_Version(4,5,0)
150- SEXP res = Rf_findVar ( nameSym, env ) ;
151- #else
152- SEXP res = R_getVarEx (nameSym, env, TRUE , R_UnboundValue);
153- #endif
154-
155- if ( res == R_UnboundValue ) throw binding_not_found (name) ;
156-
157- /* We need to evaluate if it is a promise */
158- if ( TYPEOF (res) == PROMSXP){
159- res = internal::Rcpp_eval_impl ( res, env ) ;
160- }
161- return res ;
132+ Symbol nameSym = Rf_install (name.c_str ());
133+ return find (nameSym);
162134 }
163135
164136 /* *
@@ -171,19 +143,13 @@ namespace Rcpp{
171143 SEXP env = Storage::get__ () ;
172144#if R_VERSION < R_Version(4,5,0)
173145 SEXP res = Rf_findVar ( name, env ) ;
146+ if (res == R_UnboundValue) throw binding_not_found (name.c_str ());
147+ if (TYPEOF (res) == PROMSXP)
148+ res = internal::Rcpp_eval_impl (res, env);
174149#else
175- SEXP res = R_getVarEx (name, env, TRUE , R_UnboundValue);
150+ SEXP res = R_getVarEx (name, env, TRUE , NULL );
151+ if (res == NULL ) throw binding_not_found (name.c_str ());
176152#endif
177- if ( res == R_UnboundValue ) {
178- // Pass on the const char* to the RCPP_EXCEPTION_CLASS's
179- // const std::string& requirement
180- throw binding_not_found (name.c_str ()) ;
181- }
182-
183- /* We need to evaluate if it is a promise */
184- if ( TYPEOF (res) == PROMSXP){
185- res = internal::Rcpp_eval_impl ( res, env ) ;
186- }
187153 return res ;
188154 }
189155
@@ -199,10 +165,11 @@ namespace Rcpp{
199165 SEXP nameSym = Rf_install (name.c_str ());
200166#if R_VERSION < R_Version(4,5,0)
201167 SEXP res = Rf_findVarInFrame ( Storage::get__ () , nameSym ) ;
168+ return res != R_UnboundValue;
202169#else
203- SEXP res = R_getVarEx (nameSym, Storage::get__ (), FALSE , R_UnboundValue);
170+ SEXP res = R_getVarEx (nameSym, Storage::get__ (), FALSE , NULL );
171+ return res != NULL ;
204172#endif
205- return res != R_UnboundValue ;
206173 }
207174
208175 /* *
0 commit comments