23 #ifndef Rcpp_Environment_h
24 #define Rcpp_Environment_h
32 inline SEXP as_environment(SEXP x){
33 if( Rf_isEnvironment(x) )
return x ;
34 SEXP asEnvironmentSym = Rf_install(
"as.environment");
38 }
catch(
const eval_error& ex) {
39 const char* fmt =
"Cannot convert object to an environment: "
40 "[type=%s; target=ENVSXP].";
41 throw not_compatible(fmt, Rf_type2char(TYPEOF(x)));
49 Storage::set__(R_GlobalEnv) ;
86 SEXP env = Storage::get__() ;
88 R_ObjectTable *tb = (R_ObjectTable*) R_ExternalPtrAddr(HASHTAB(env));
89 return tb->objects(tb) ;
91 return R_lsInternal( env,
all ? TRUE : FALSE ) ;
103 SEXP
get(
const std::string& name)
const {
104 SEXP env = Storage::get__() ;
105 SEXP nameSym = Rf_install(name.c_str());
106 SEXP res = Rf_findVarInFrame( env, nameSym ) ;
108 if( res == R_UnboundValue )
return R_NilValue ;
111 if( TYPEOF(res) == PROMSXP){
125 SEXP env = Storage::get__() ;
126 SEXP res = Rf_findVarInFrame( env, name ) ;
128 if( res == R_UnboundValue )
return R_NilValue ;
131 if( TYPEOF(res) == PROMSXP){
145 SEXP
find(
const std::string& name)
const{
146 SEXP env = Storage::get__() ;
147 SEXP nameSym = Rf_install(name.c_str());
148 SEXP res = Rf_findVar( nameSym, env ) ;
150 if( res == R_UnboundValue )
throw binding_not_found(name) ;
153 if( TYPEOF(res) == PROMSXP){
166 SEXP env = Storage::get__() ;
167 SEXP res = Rf_findVar( name, env ) ;
169 if( res == R_UnboundValue ) {
172 throw binding_not_found(name.c_str()) ;
176 if( TYPEOF(res) == PROMSXP){
190 bool exists(
const std::string& name )
const {
191 SEXP nameSym = Rf_install(name.c_str());
192 SEXP res = Rf_findVarInFrame( Storage::get__() , nameSym ) ;
193 return res != R_UnboundValue ;
207 bool assign(
const std::string& name, SEXP x )
const{
209 SEXP nameSym = Rf_install(name.c_str());
210 Rf_defineVar( nameSym, x, Storage::get__() );
215 return assign(name, (SEXP) x);
226 template <
typename WRAPPABLE>
227 bool assign(
const std::string& name,
const WRAPPABLE& x)
const ;
234 return R_EnvironmentIsLocked(Storage::get__());
243 throw binding_is_locked(name) ;
247 SEXP internalSym = Rf_install(
".Internal" );
248 SEXP removeSym = Rf_install(
"remove" );
250 Shield<SEXP> call(Rf_lang2(internalSym, Rf_lang4(removeSym, str, Storage::get__(), Rf_ScalarLogical(FALSE))));
254 throw no_such_binding(name) ;
264 void lock(
bool bindings =
false) {
265 R_LockEnvironment( Storage::get__(), bindings ? TRUE: FALSE ) ;
275 if( !
exists( name) )
throw no_such_binding(name) ;
276 SEXP nameSym = Rf_install(name.c_str());
277 R_LockBinding( nameSym, Storage::get__() );
287 if( !
exists( name) )
throw no_such_binding(name) ;
288 SEXP nameSym = Rf_install(name.c_str());
289 R_unLockBinding( nameSym, Storage::get__() );
301 if( !
exists( name) )
throw no_such_binding(name) ;
302 SEXP nameSym = Rf_install(name.c_str());
303 return R_BindingIsLocked(nameSym, Storage::get__() ) ;
316 if( !
exists( name) )
throw no_such_binding(name) ;
317 SEXP nameSym = Rf_install(name.c_str());
318 return R_BindingIsActive(nameSym, Storage::get__()) ;
325 SEXP env = Storage::get__() ;
326 return OBJECT(env) && Rf_inherits(env,
"UserDefinedDatabase") ;
354 return R_BaseNamespace ;
374 SEXP getNamespaceSym = Rf_install(
"getNamespace");
375 Shield<SEXP> package_str( Rf_mkString(package.c_str()) );
376 Shield<SEXP> call( Rf_lang2(getNamespaceSym, package_str) );
379 throw no_such_namespace( package ) ;
395 SEXP newEnvSym = Rf_install(
"new.env");
396 Shield<SEXP> call(Rf_lang3(newEnvSym, Rf_ScalarLogical(hashed), Storage::get__()));
#define RCPP_GENERATE_CTOR_ASSIGN(__CLASS__)
attribute_hidden SEXP get_Rcpp_namespace()
SEXP Rcpp_eval_impl(SEXP expr, SEXP env)
void lockBinding(const std::string &name)
bool remove(const std::string &name)
static Environment_Impl global_env()
static Environment_Impl Rcpp_namespace()
bool is_user_database() const
void lock(bool bindings=false)
bool assign(const std::string &name, SEXP x) const
void unlockBinding(const std::string &name)
sugar::All< NA, T > all(const Rcpp::VectorBase< LGLSXP, NA, T > &t)
RCPP_API_CLASS(DottedPair_Impl)
SEXP Rcpp_fast_eval(SEXP expr, SEXP env)
SEXP get(const std::string &name) const
SEXP find(const std::string &name) const
static Environment_Impl base_env()
static Environment_Impl namespace_env(const std::string &package)
static Environment_Impl empty_env()
bool bindingIsLocked(const std::string &name) const
Environment_Impl parent() const
static Environment_Impl base_namespace()
Environment_Impl< PreserveStorage > Environment
Environment_Impl new_child(bool hashed) const
Symbol_Impl< NoProtectStorage > Symbol
bool exists(const std::string &name) const
bool bindingIsActive(const std::string &name) const