Discussion:
[Rcpp-devel] NULL value passed as symbol address with all C++ functions
Barth Riley
2018-11-07 20:49:14 UTC
Permalink
I apologize if this question has been asked before but after doing several searches I could not find an answer that is directly applicable to my problem. I am working on a package containing a number of Rcpp functions. The package builds and loads without a problem. However, when I call any of the Rcpp functions from within R, I get the following type of error message:

Error in .Call(<pointer: (nil)>, x, xMin, xMax, adjustment) :
NULL value passed as symbol address

As an example, here is the function that returned the error in the C++ file:

// [[Rcpp::export]]
NumericVector logit(Rcpp::NumericVector x,
Rcpp::NumericVector xMin,
Rcpp::NumericVector xMax,
double adjustment = 0.3) {

...

}

The exported function in RcppExports.cpp:

// logit
NumericVector logit(Rcpp::NumericVector x, Rcpp::NumericVector xMin, Rcpp::NumericVector xMax, double adjustment);
RcppExport SEXP _MFRM_logit(SEXP xSEXP, SEXP xMinSEXP, SEXP xMaxSEXP, SEXP adjustmentSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< Rcpp::NumericVector >::type x(xSEXP);
Rcpp::traits::input_parameter< Rcpp::NumericVector >::type xMin(xMinSEXP);
Rcpp::traits::input_parameter< Rcpp::NumericVector >::type xMax(xMaxSEXP);
Rcpp::traits::input_parameter< double >::type adjustment(adjustmentSEXP);
rcpp_result_gen = Rcpp::wrap(logit(x, xMin, xMax, adjustment));
return rcpp_result_gen;
END_RCPP
}

And the corresponding R file:

logit <- function(x, xMin, xMax, adjustment = 0.3) {
.Call(`_MFRM_logit`, x, xMin, xMax, adjustment)
}

First, how can there be two functions called "logit"--one in the main C++ file and one in RcppExports.cpp? And where does _MFRM_logit get defined? Might this be causing the problem?

I should note that hte problem is not limited to this one function, but to all the exported C++ functions.

Second, is there some option in the project or in the C++ files that needs to be set?

I am running R 3.51, RStudio 1.14, and Rcpp (0.12.19).
Dirk Eddelbuettel
2018-11-08 02:35:18 UTC
Permalink
On 7 November 2018 at 14:49, Barth Riley wrote:
| I apologize if this question has been asked before but after doing several searches I could not find an answer that is directly applicable to my problem. I am working on a package containing a number of Rcpp functions. The package builds and loads without a problem. However, when I call any of the Rcpp functions from within R, I get the following type of error message:
|
| Error in .Call(<pointer: (nil)>, x, xMin, xMax, adjustment) :
| NULL value passed as symbol address

Something went wrong here.

And we can't tell from the incomplete example you posted.

I suggest you start fresh with a new baby package (maybe via
Rcpp.package.skeleton, maybe via the RStudio helper), see that that works (it
should, does for everybody else and testing) and then add to it, slowly and
carefully. With some care the difference should eventually reveal itself.

| As an example, here is the function that returned the error in the C++ file:
|
| // [[Rcpp::export]]
| NumericVector logit(Rcpp::NumericVector x,
| Rcpp::NumericVector xMin,
| Rcpp::NumericVector xMax,
| double adjustment = 0.3) {
|
| ...
|
| }
|
| The exported function in RcppExports.cpp:
|
| // logit
| NumericVector logit(Rcpp::NumericVector x, Rcpp::NumericVector xMin, Rcpp::NumericVector xMax, double adjustment);
| RcppExport SEXP _MFRM_logit(SEXP xSEXP, SEXP xMinSEXP, SEXP xMaxSEXP, SEXP adjustmentSEXP) {
| BEGIN_RCPP
| Rcpp::RObject rcpp_result_gen;
| Rcpp::RNGScope rcpp_rngScope_gen;
| Rcpp::traits::input_parameter< Rcpp::NumericVector >::type x(xSEXP);
| Rcpp::traits::input_parameter< Rcpp::NumericVector >::type xMin(xMinSEXP);
| Rcpp::traits::input_parameter< Rcpp::NumericVector >::type xMax(xMaxSEXP);
| Rcpp::traits::input_parameter< double >::type adjustment(adjustmentSEXP);
| rcpp_result_gen = Rcpp::wrap(logit(x, xMin, xMax, adjustment));
| return rcpp_result_gen;
| END_RCPP
| }
|
| And the corresponding R file:
|
| logit <- function(x, xMin, xMax, adjustment = 0.3) {
| .Call(`_MFRM_logit`, x, xMin, xMax, adjustment)
| }
|
| First, how can there be two functions called "logit"--one in the main C++ file and one in RcppExports.cpp? And where does _MFRM_logit get defined? Might this be causing the problem?

Not a problem per se. The one here is a just a declaration -- standard C and
C++ practice.
|
| I should note that hte problem is not limited to this one function, but to all the exported C++ functions.
|
| Second, is there some option in the project or in the C++ files that needs to be set?

I don't understand your question -- but we try to document all necessary
steps.

Dirk

| I am running R 3.51, RStudio 1.14, and Rcpp (0.12.19).
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-***@lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
http://dirk.eddelbuettel.com | @eddelbuettel | ***@debian.org
Barth Riley
2018-11-08 04:53:09 UTC
Permalink
@Dirk: I didn’t want to overwhelm those on the list with tons of code. Below is the full source for the function. What else would you need to see?

After clearing my environment variables, I am now getting the following error:

Error in logit(30, 0, 100) :
function 'enterRNGScope' not provided by package 'Rcpp'

I do have some roxygen documentation errors in my package? Might this have an effect in producing the error?

Here is the function:

// [[Rcpp::export]]
Rcpp::NumericVector logit(Rcpp::NumericVector x,
Rcpp::NumericVector xMin,
Rcpp::NumericVector xMax,
double adjustment = 0.3) {

int N = x.length();
int nMin = xMin.length();
int nMax = xMax.length();

Rcpp::NumericVector logOgive(N,0.0);


if(!(nMin == 1 || nMin == N))
return logOgive;
if(!(nMax == 1 || nMax == N))
return logOgive;
if(xMin.length() != xMax.length())
return logOgive;

int justOne;
if(xMin.length() == 1)
justOne = 1;
else
justOne = 0;

NumericVector upperBound = xMax - adjustment;
NumericVector lowerBound = xMin + adjustment;

for(int i = 0; i < N; i++) {
if(x[i] < 0) continue;
if(justOne == 1) {
if(x[i] <= xMin[0]) x[i] = lowerBound[i];
if(x[i] >= xMax[0]) x[i] = upperBound[i];
logOgive[i] = log((x[i] - xMin[0])/(xMax[0] - x[i]));
} else {
if(x[i] <= xMin[i]) x[i] = lowerBound[i];
if(x[i] >= xMax[i]) x[i] = upperBound[i];
logOgive[i] = log((x[i] - xMin[i])/(xMax[i] - x[i]));
}
}

return logOgive;
}

Barth
Dirk Eddelbuettel
2018-11-08 12:32:42 UTC
Permalink
On 7 November 2018 at 22:53, Barth Riley wrote:
| @Dirk: I didn’t want to overwhelm those on the list with tons of code. Below is the full source for the function. What else would you need to see?
|
| After clearing my environment variables, I am now getting the following error:
|
| Error in logit(30, 0, 100) :
| function 'enterRNGScope' not provided by package 'Rcpp'

Someting more fundamental may be out of line as that is _of course_ part of
Rcpp and provided. Maybe you don't importFrom(Rcpp, evalCpp) in NAMESPACE or
declare the dyn.lib wrong.

| I do have some roxygen documentation errors in my package? Might this have an effect in producing the error?

No, just check CRAN -- hundreds of Rcpp packages use roxygen.

Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | ***@debian.org
Barth Riley
2018-11-08 15:10:08 UTC
Permalink
In my “stupid” (minimal) project, my namespace looks as follows:

useDynLib(StupidRCPP, .registration=TRUE)
exportPattern("^[[:alpha:]]+")
importFrom(Rcpp, evalCpp)

In my main project I include Rcpp in an import() statement in NAMESPACE.

One thing I’m noticing with the minimal project is that I can build it without errors and access functions from the package but devtools::check() reports syntax errors
though these errors appear to be from an old version of the code (it has been quite a headache manually deleting all of the files in .Rcheck, RprojUser, and the Rtmp
 folders.

Barth
Jeff Newmiller
2018-11-08 15:25:21 UTC
Permalink
Did you remove the .Rbuildignore file? Your problems should not be problems if that file is configured.
Post by Barth Riley
useDynLib(StupidRCPP, .registration=TRUE)
exportPattern("^[[:alpha:]]+")
importFrom(Rcpp, evalCpp)
In my main project I include Rcpp in an import() statement in
NAMESPACE.
One thing I’m noticing with the minimal project is that I can build it
without errors and access functions from the package but
devtools::check() reports syntax errors…though these errors appear to
be from an old version of the code (it has been quite a headache
manually deleting all of the files in .Rcheck, RprojUser, and the Rtmp…
folders.
Barth
--
Sent from my phone. Please excuse my brevity.
Continue reading on narkive:
Loading...