[R-pkg-devel] Unable to access log operator in C

Avraham Adler @vr@h@m@@d|er @end|ng |rom gm@||@com
Wed Feb 28 18:05:20 CET 2024


I am hoping the solution to this question is simple, but I have not
been able to find one. I am building a routine in C to be called from
R. I am including Rmath.h. However, when I have a call to "log", I get
the error "called object 'log' is not a function or a function
pointer. When I "trick" it by calling log1p(x - 1), which I *know* is
exported from Rmath.h, it works.

More completely, my includes are:
#include <R.h>
#include <Rmath.h>
#include <Rinternals.h>
#include <Rconfig.h>
#include <stdlib.h> // for NULL
#include <R_ext/Rdynload.h>

The object being logged is a double, passed into C as an SEXP, call it
"a", which for now will always be a singleton. I initialize a pointer
double *pa = REAL(a). I eventually call log(pa[0]), which does not
compile and throws the error listed above. Switching the call to
log1p(pa[0] - 1.0) works and returns the proper answer.

Even including math.h explicitly does not help, which makes sense as
it is included by Rmath.h.

Thank you,

Avi



More information about the R-package-devel mailing list