Skip to content

Commit 921e7d6

Browse files
kevinusheyeddelbuettel
authored andcommitted
use public R APIs for new_env (#785)
* use public R APIs for new_env * grab 'new.env()' directly from base namespace
1 parent c3b26f6 commit 921e7d6

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2017-12-05 Kevin Ushey <[email protected]>
2+
3+
* inst/include/Rcpp/Environment.h: Use public R APIs
4+
* inst/include/Rcpp/api/meat/Environment.h: Idem
5+
16
2017-12-04 Kevin Ushey <[email protected]>
27

38
* inst/include/Rcpp/RObject.h: Protect temporary wrapped SEXPs

inst/include/Rcpp/Environment.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
#ifndef Rcpp_Environment_h
2424
#define Rcpp_Environment_h
2525

26-
// From 'R/Defn.h'
27-
// NOTE: can't include header directly as it checks for some C99 features
28-
extern "C" SEXP R_NewHashedEnv(SEXP, SEXP);
29-
3026
namespace Rcpp{
3127

3228
RCPP_API_CLASS(Environment_Impl),
@@ -406,21 +402,6 @@ namespace Rcpp{
406402

407403
typedef Environment_Impl<PreserveStorage> Environment ;
408404

409-
inline Environment new_env(int size = 29) {
410-
Shield<SEXP> sizeSEXP(Rf_ScalarInteger(size));
411-
return R_NewHashedEnv(R_EmptyEnv, sizeSEXP);
412-
}
413-
414-
inline Environment new_env(SEXP parent, int size = 29) {
415-
Shield<SEXP> sizeSEXP(Rf_ScalarInteger(size));
416-
Shield<SEXP> parentSEXP(parent);
417-
if (!Rf_isEnvironment(parentSEXP)) {
418-
stop("parent is not an environment");
419-
}
420-
return R_NewHashedEnv(parentSEXP, sizeSEXP);
421-
}
422-
423-
424405
} // namespace Rcpp
425406

426407
#endif

inst/include/Rcpp/api/meat/Environment.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ Environment_Impl<StoragePolicy>::Environment_Impl( int pos ){
4444
Storage::set__(env) ;
4545
}
4646

47+
inline Environment new_env(int size = 29) {
48+
Function newEnv("new.env", R_BaseNamespace);
49+
return newEnv(_["size"] = size, _["parent"] = R_EmptyEnv);
50+
}
51+
52+
inline Environment new_env(SEXP parent, int size = 29) {
53+
Function newEnv("new.env", R_BaseNamespace);
54+
return newEnv(_["size"] = size, _["parent"] = parent);
55+
}
4756

4857
} // namespace Rcpp
4958

0 commit comments

Comments
 (0)