@@ -95,20 +95,8 @@ namespace Rcpp{
9595 * @return a SEXP (possibly R_NilValue)
9696 */
9797 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 ;
98+ Symbol nameSym = Rf_install (name.c_str ());
99+ return get (nameSym);
112100 }
113101
114102 /* *
@@ -122,16 +110,12 @@ namespace Rcpp{
122110 SEXP env = Storage::get__ () ;
123111#if R_VERSION < R_Version(4,5,0)
124112 SEXP res = Rf_findVarInFrame ( env, name ) ;
113+ if (res == R_UnboundValue) return R_NilValue;
114+ if (TYPEOF (res) == PROMSXP)
115+ res = internal::Rcpp_eval_impl (res, env);
125116#else
126- SEXP res = R_getVarEx (name, env, FALSE , R_UnboundValue );
117+ SEXP res = R_getVarEx (name, env, FALSE , R_NilValue );
127118#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- }
135119 return res ;
136120 }
137121
@@ -144,21 +128,8 @@ namespace Rcpp{
144128 *
145129 */
146130 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 ;
131+ Symbol nameSym = Rf_install (name.c_str ());
132+ return find (nameSym);
162133 }
163134
164135 /* *
@@ -171,19 +142,13 @@ namespace Rcpp{
171142 SEXP env = Storage::get__ () ;
172143#if R_VERSION < R_Version(4,5,0)
173144 SEXP res = Rf_findVar ( name, env ) ;
145+ if (res == R_UnboundValue) throw binding_not_found (name.c_str ());
146+ if (TYPEOF (res) == PROMSXP)
147+ res = internal::Rcpp_eval_impl (res, env);
174148#else
175- SEXP res = R_getVarEx (name, env, TRUE , R_UnboundValue);
149+ SEXP res = R_getVarEx (name, env, TRUE , NULL );
150+ if (res == NULL ) throw binding_not_found (name.c_str ());
176151#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- }
187152 return res ;
188153 }
189154
@@ -199,10 +164,11 @@ namespace Rcpp{
199164 SEXP nameSym = Rf_install (name.c_str ());
200165#if R_VERSION < R_Version(4,5,0)
201166 SEXP res = Rf_findVarInFrame ( Storage::get__ () , nameSym ) ;
167+ return res != R_UnboundValue;
202168#else
203- SEXP res = R_getVarEx (nameSym, Storage::get__ (), FALSE , R_UnboundValue);
169+ SEXP res = R_getVarEx (nameSym, Storage::get__ (), FALSE , NULL );
170+ return res != NULL ;
204171#endif
205- return res != R_UnboundValue ;
206172 }
207173
208174 /* *
@@ -389,7 +355,11 @@ namespace Rcpp{
389355 * The parent environment of this environment
390356 */
391357 Environment_Impl parent () const {
358+ #if R_VERSION < R_Version(4,5,0)
392359 return Environment_Impl ( ENCLOS (Storage::get__ ()) ) ;
360+ #else
361+ return Environment_Impl (R_ParentEnv (Storage::get__ ()));
362+ #endif
393363 }
394364
395365 /* *
0 commit comments