From 124dc10a92356948f0111bc053982d82543d9520 Mon Sep 17 00:00:00 2001 From: Peter Meilstrup Date: Mon, 1 Jul 2024 12:41:05 -0700 Subject: [PATCH] backport R_existsVarInFrame --- src/vadr.c | 16 ++++++++++++++++ src/vadr.h | 12 +++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/vadr.c b/src/vadr.c index 6cc7750..c2b08cd 100644 --- a/src/vadr.c +++ b/src/vadr.c @@ -62,3 +62,19 @@ SEXP new_weird_promise(SEXP expr, SEXP env, SEXP value) { UNPROTECT(1); return out; } + +#if R_VERSION < R_Version(4, 4, 1) +SEXP allocLang(int n) +{ + if (n > 0) + return LCONS(R_NilValue, allocList(n - 1)); + else + return R_NilValue; +} +#endif + +#if R_VERSION < R_Version(4, 2, 0) +Rboolean R_existsVarInFrame(SEXP rho, SEXP symbol) { + return (Rf_findVarInFrame3(rho, symbol, FALSE) != R_UnboundValue); +} +#endif diff --git a/src/vadr.h b/src/vadr.h index 979be85..1d12920 100644 --- a/src/vadr.h +++ b/src/vadr.h @@ -66,13 +66,7 @@ SEXP peek_promise(SEXP prom); #endif #if R_VERSION < R_Version(4, 4, 1) -SEXP allocLang(int n) -{ - if (n > 0) - return LCONS(R_NilValue, allocList(n - 1)); - else - return R_NilValue; -} +SEXP allocLang(int n); #endif #if R_VERSION < R_Version(4, 5, 0) @@ -80,3 +74,7 @@ SEXP allocLang(int n) # define R_ClosureEnv(x) CLOENV(x) # define R_ParentEnv(x) ENCLOS(x) #endif + +#if R_VERSION < R_Version(4, 2, 0) +Rboolean R_existsVarInFrame(SEXP rho, SEXP symbol); +#endif