Skip to content
Prev 503 / 10988 Next

[Rcpp-devel] Extract a function from a list and create a call

On Sat, Mar 20, 2010 at 2:53 AM, Romain Francois
<romain at r-enthusiasts.com> wrote:
I can run your example without a problem but when I try to go to the
next stage and extract the character vectors from a list, it seems
that internally the conversion to a STRSXP has not been completed (or
something like that).  Attempts to extract the first string from the
CharacterVector extracted by name from the list fail with an error
message of
Assigned fam of length 1, llink of length 1
Error in fx(binomial()) :
  STRING_ELT() can only be applied to a 'character vector', not a 'symbol'

The test script is

suppressWarnings(require(inline))
suppressWarnings(require(Rcpp))

fx <- cfunction( signature( l = "list" ), '
    List ll(l);
    CharacterVector fam = ll["family"], llink = ll["link"];
    Rprintf("Assigned fam of length %d, llink of length %d\\n",
	    fam.size(), llink.size());
    char *fpt = (char *)0, *lpt = (char *)0;
    if (fam.size()) fpt = fam[0];
    if (llink.size()) lpt = llink[0];
    return List::create(_["fam"] = std::string(fpt),
                        _["llink"] = std::string(lpt));
', Rcpp = TRUE, includes = "using namespace Rcpp;" )

fx(binomial())
fx(gaussian())
fx(poisson())