> Shield<SEXP> res(Rcpp_fast_eval(Rf_lang2(asEnvironmentSym, x), R_GlobalEnv));The call should be protected before evaluation though. So more like: Shield<SEXP> call(Rf_lang2(asEnvironmentSym, x)); return Rcpp_fast_eval(call, R_GlobalEnv); Best, Lionel On 3/23/20, Dirk Eddelbuettel <edd at debian.org> wrote:> > > On 23 March 2020 at 17:07, Ben Bolker wrote: > | Or is there a way I can use Shield() since this an Rcpp-based project > | anyway? > > Yes you can, and I would recommend it. > > Example from Rcpp itself, file Environment.h: > > Shield<SEXP> res(Rcpp_fast_eval(Rf_lang2(asEnvironmentSym, x), > R_GlobalEnv)); > > For Rcpp_fast_eval, you may still need to #define RCPP_USE_UNWIND_PROTECT > before including Rcpp.h; as I recall we were seeing too many side effects > in > other packages when globally enabling it. Or you can play it safe and > simply > use Rcpp_eval. > > This really was more of a rcpp-devel question. > > Dirk > > -- > http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >
Dirk Eddelbuettel
2020-Mar-24  12:19 UTC
[Rd] help with rchk warnings on Rf_eval(Rf_lang2(...))
On 24 March 2020 at 11:39, Lionel Henry wrote:
| > Shield<SEXP> res(Rcpp_fast_eval(Rf_lang2(asEnvironmentSym, x),
R_GlobalEnv));
| 
| The call should be protected before evaluation though. So more like:
| 
| Shield<SEXP> call(Rf_lang2(asEnvironmentSym, x));
| return Rcpp_fast_eval(call, R_GlobalEnv);
Good catch.
And recursive grep for Rf_lang2 in the Rcpp sources tree suggests this is as the
common pattern in all other instances.
Dirk
edd at rob:~/git/rcpp(master)$ ag Rf_lang2 inst/include/
inst/include/Rcpp/exceptions.h
360:        Rcpp::Shield<SEXP>
simpleErrorExpr(Rf_lang2(::Rf_install("simpleError"), txt));
365:        Rcpp::Shield<SEXP> simpleErrorExpr(
Rf_lang2(::Rf_install("simpleError"), tryError ));
388:    Rcpp::Shield<SEXP> expr( Rf_lang2( stop_sym , condition ) ) ;
395:    Rcpp::Shield<SEXP> expr( Rf_lang2( stop_sym , condition ) ) ;
inst/include/Rcpp/Reference.h
62:            Shield<SEXP> call(Rf_lang2(newSym, str));
inst/include/Rcpp/api/meat/Rcpp_eval.h
99:            Shield<SEXP>
conditionMessageCall(::Rf_lang2(::Rf_install("conditionMessage"),
res));
inst/include/Rcpp/macros/macros.h
69:       SEXP expr = PROTECT( Rf_lang2( stop_sym , rcpp_output_condition ) ) ; 
\
inst/include/Rcpp/Environment.h
36:                Shield<SEXP>
res(Rcpp_fast_eval(Rf_lang2(asEnvironmentSym, x), R_GlobalEnv));
250:                    Shield<SEXP> call(Rf_lang2(internalSym,
Rf_lang4(removeSym, str, Storage::get__(), Rf_ScalarLogical(FALSE))));
376:                Shield<SEXP> call( Rf_lang2(getNamespaceSym,
package_str) );
inst/include/Rcpp/r_cast.h
34:                Shield<SEXP> call(Rf_lang2(funSym, x));
117:                    Shield<SEXP> call( Rf_lang2( Rf_install(
"as.character" ), x ) );
inst/include/Rcpp/Module.h
456:    Shield<SEXP> __load_module_call__( Rf_lang2( GET_MODULE_SYM,
_rcpp_module_boot_##NAME() ) ); \
inst/include/Rcpp/lang.h
26:#define Rcpp_lang2 Rf_lang2
edd at rob:~/git/rcpp(master)$ 
-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
Dirk Eddelbuettel
2020-Mar-24  13:11 UTC
[Rd] help with rchk warnings on Rf_eval(Rf_lang2(...))
On 24 March 2020 at 07:19, Dirk Eddelbuettel wrote: | On 24 March 2020 at 11:39, Lionel Henry wrote: | | > Shield<SEXP> res(Rcpp_fast_eval(Rf_lang2(asEnvironmentSym, x), R_GlobalEnv)); | | | | The call should be protected before evaluation though. So more like: | | | | Shield<SEXP> call(Rf_lang2(asEnvironmentSym, x)); | | return Rcpp_fast_eval(call, R_GlobalEnv); | | Good catch. Fixed in https://github.com/RcppCore/Rcpp/pull/1059 along with another instance from further down in the same file. Thanks to Romain and Lionel for spotting this. Dirk -- http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org