Skip to content

Piping code into cppFunction()? #696

@richgoldberg

Description

@richgoldberg

It seems that piping text containing a C++ function into cppFunction() doesn't lead to the function becoming part of the environment. (code is the first argument fo cppFunction() so I thought that it should work.)

Here's an example that didn't work for me:

'int fibonacci(const int x) {
    if (x == 0) return(0); 
    if (x == 1) return(1);
    return (fibonacci(x - 1)) + fibonacci(x - 2);
    }' %>% cppFunction()

In contrast, this worked perfectly for me:

cppFunction(
    'int fibonacci(const int x) {
        if (x == 0) return(0); 
        if (x == 1) return(1);
        return (fibonacci(x - 1)) + fibonacci(x - 2);
    }')

(I am using R version 3.4.0 on 64 bit Windows 7 with version 0.12.10 of Rcpp.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions