I am creating an R package that I intend to submit to CRAN that has a function calling a routine written in C. How do I load the compiled C routine in the R function in platform-independent way? I am able to make my package work on my intel-based Mac with:
function(mydata)
{
dyn.load(file.path(.Library,"mypkg/libs/i386",paste("mypkg", .Platform$dynlib.ext, sep="")))
try(
output <- .C("myfunc_cversion",
in_data = as.double(mydata),
res_data = as.double(res),
PACKAGE = "mypkg")
)
result <- as.matrix(output$res_data)
return(result)
}
The problem is the call to dyn.load where I cannot figure out how to specify the full path to the shared library for my installed package in a portable way.
Is there another variable in R besides .Library that I should use, or is there a better function than dyn.load for this case?