[Rcpp-devel] Getting an R option in Rcpp

Rguy rguy at 123mail.org
Sat Aug 1 19:16:19 CEST 2015


Yes, that's exactly what I was looking for. Although I'd return an integer:

// [[Rcpp::export]]
IntegerVector foo_int() {
  Function opt("getOption");
  IntegerVector x = opt("digits");
  return x;
}


On Sat, Aug 1, 2015 at 5:15 PM, Søren Højsgaard <sorenh at math.aau.dk> wrote:

> Something like
>
>
>
> #include <Rcpp.h>
>
> using namespace Rcpp;
>
>
>
> // [[Rcpp::export]]
>
> CharacterVector foo() {
>
>   Function opt("getOption");
>
>   CharacterVector x = opt("digits");
>
>   return x;
>
> }
>
>
>
> /*** R
>
> foo()
>
> */
>
>
>
> > foo()
>
> [1] "7"
>
>
>
> - all though the result is here a character.
>
>
>
> Regards
>
> Søren
>
>
>
>
>
> *From:* rcpp-devel-bounces at lists.r-forge.r-project.org [mailto:
> rcpp-devel-bounces at lists.r-forge.r-project.org] *On Behalf Of *Rguy
> *Sent:* 1. august 2015 08:07
> *To:* Rcpp
> *Subject:* [Rcpp-devel] Getting an R option in Rcpp
>
>
>
> Can I access an R option from within an Rcpp function? I'd like the access
> to happen at runtime, not at compile time. Something like this:
>
>
>
> if (getOption("my_option") == x) {
>
>   do this;
>
> } else {
>
>   do that;
>
> }
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150801/4ce823c7/attachment.html>


More information about the Rcpp-devel mailing list