1- // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2- //
1+
32// Environment.h: Rcpp R/C++ interface class library -- access R environments
43//
54// Copyright (C) 2009 - 2013 Dirk Eddelbuettel and Romain Francois
6- // Copyright (C) 2014 - 2020 Dirk Eddelbuettel, Romain Francois and Kevin Ushey
5+ // Copyright (C) 2014 - 2025 Dirk Eddelbuettel, Romain Francois and Kevin Ushey
76//
87// This file is part of Rcpp.
98//
@@ -98,8 +97,11 @@ namespace Rcpp{
9897 SEXP get (const std::string& name) const {
9998 SEXP env = Storage::get__ () ;
10099 SEXP nameSym = Rf_install (name.c_str ());
100+ #if R_VERSION < R_Version(4,5,0)
101101 SEXP res = Rf_findVarInFrame ( env, nameSym ) ;
102-
102+ #else
103+ SEXP res = R_getVarEx (nameSym, env, FALSE , R_UnboundValue);
104+ #endif
103105 if ( res == R_UnboundValue ) return R_NilValue ;
104106
105107 /* We need to evaluate if it is a promise */
@@ -118,7 +120,11 @@ namespace Rcpp{
118120 */
119121 SEXP get (Symbol name) const {
120122 SEXP env = Storage::get__ () ;
123+ #if R_VERSION < R_Version(4,5,0)
121124 SEXP res = Rf_findVarInFrame ( env, name ) ;
125+ #else
126+ SEXP res = R_getVarEx (name, env, FALSE , R_UnboundValue);
127+ #endif
122128
123129 if ( res == R_UnboundValue ) return R_NilValue ;
124130
@@ -140,7 +146,11 @@ namespace Rcpp{
140146 SEXP find ( const std::string& name) const {
141147 SEXP env = Storage::get__ () ;
142148 SEXP nameSym = Rf_install (name.c_str ());
149+ #if R_VERSION < R_Version(4,5,0)
143150 SEXP res = Rf_findVar ( nameSym, env ) ;
151+ #else
152+ SEXP res = R_getVarEx (nameSym, env, TRUE , R_UnboundValue);
153+ #endif
144154
145155 if ( res == R_UnboundValue ) throw binding_not_found (name) ;
146156
@@ -159,8 +169,11 @@ namespace Rcpp{
159169 */
160170 SEXP find (Symbol name) const {
161171 SEXP env = Storage::get__ () ;
172+ #if R_VERSION < R_Version(4,5,0)
162173 SEXP res = Rf_findVar ( name, env ) ;
163-
174+ #else
175+ SEXP res = R_getVarEx (name, env, TRUE , R_UnboundValue);
176+ #endif
164177 if ( res == R_UnboundValue ) {
165178 // Pass on the const char* to the RCPP_EXCEPTION_CLASS's
166179 // const std::string& requirement
@@ -184,7 +197,11 @@ namespace Rcpp{
184197 */
185198 bool exists ( const std::string& name ) const {
186199 SEXP nameSym = Rf_install (name.c_str ());
200+ #if R_VERSION < R_Version(4,5,0)
187201 SEXP res = Rf_findVarInFrame ( Storage::get__ () , nameSym ) ;
202+ #else
203+ SEXP res = R_getVarEx (nameSym, Storage::get__ (), FALSE , R_UnboundValue);
204+ #endif
188205 return res != R_UnboundValue ;
189206 }
190207
0 commit comments