[Rcpp-devel] NULL value passed as symbol address

Kamil Slowikowski kslowikowski at gmail.com
Thu Oct 16 20:41:25 CEST 2014


Why must I call my C++ function using the `.Call()` syntax? Why can't I
call it by name? Other C++ functions in my package do not have this
problem. It's just this one that has the NULL symbol address.

```
> library(kamlib)

Attaching package: ‘kamlib’

> expected_errors(c('####'))
Error in .Primitive(".Call")(<pointer: 0x0>, xs) :
  NULL value passed as symbol address

> .Call('kamlib_expected_errors', PACKAGE = 'kamlib', c('####'))
[1] 2.52384
```

I created a package called 'kamlib'. In that package, I have a C++ file
called 'expected_errors.cpp' with this code:

```
#include <Rcpp.h>
#include <string.h>
using namespace Rcpp;

// [[Rcpp::export]]
NumericVector expected_errors(CharacterVector xs) {
  const double probs[] = {
    0.79433, 0.63096, 0.50119, 0.39811, 0.31623, 0.25119, 0.19953,
    0.15849, 0.12589, 0.10000, 0.07943, 0.06310, 0.05012, 0.03981,
    0.03162, 0.02512, 0.01995, 0.01585, 0.01259, 0.01000, 0.00794,
    0.00631, 0.00501, 0.00398, 0.00316, 0.00251, 0.00200, 0.00158,
    0.00126, 0.00100, 0.00079, 0.00063, 0.00050, 0.00040, 0.00032,
    0.00025, 0.00020, 0.00016, 0.00013, 0.00010, 0.00008
  };
  NumericVector res(xs.size());
  for (int i = 0; i < xs.size(); i++) {
    for (int j = 0; j < strlen(xs[i]); j++) {
      res[i] += probs[ (int) xs[i][j] - 34 ];
    }
  }
  return res;
}
```

My `RcppExports.R` file looks perfectly fine:

```
# This file was generated by Rcpp::compileAttributes
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

expected_errors <- function(xs) {
    .Call('kamlib_expected_errors', PACKAGE = 'kamlib', xs)
}

sos <- function(xs) {
    .Call('kamlib_sos', PACKAGE = 'kamlib', xs)
}
```
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20141016/5bd9ba76/attachment.html>


More information about the Rcpp-devel mailing list