I am writing an R package, and started to include C code in it. Following instructions from here, under "getting started with .C()", I created a c function in src/, and an r wrapper to it, linking via the roxygen tag @useDynLib(<package-name>, <name_of_c_function>)
.
However, after running devtools::document()
, I get the following error:
Error in FUN(X[[i]], ...) :
no such symbol <name_of_c_function> in package C:/path/to/package/src/<package-name>.dll
I read that updating R and Rtools have fixed the issue for some. I have updated both of them yesterday, but to no avail.
Any help will be much appreciated.
(This is similar to the problem in this question, which is currently unanswered.)
(It may also be related with this question, except that I use devtools::document() instead of R CMD in that question.)
Relevant code:
# R file
#' @useDynLib <package-name> <name_of_c_function>
#' @export
name_of_func <- function(y) {
stopifnot(is.numeric(y))
.C(name_of_c_function, y,y,length(y),1) [[2]]
}
// C file
<#include stdlib.h>
static void name_of_c_function(double* y, double* x,
const unsigned int length, const double a) {...}