This is my first question and I'll try to do my best to write a good one. Please let me know if you need any other information.
I'm going to start with a brief background so you can understand what I'm trying to accomplish and why. Then I'll ask my specific question.
I'm currently developing a package using Rcpp/RcppGSL. I'm using C/C++ because some of the computations I'll be doing will be over very large data sets and they need to be fast. (I'm also a research assistant; I don't always get to choose how we do things.) I'm definitely a novice with respect to C/C++. And to my understanding, C is (almost) a subset of C++. So, I've taken this to mean that I can, essentially, import and run all of my C code as C++ code (sans a few changes). Therefore, I should be able to integrate my C code into an R package using Rcpp/RcppGSL.
After I had all of my C code working, I started actually assembling the R package. I realize now this was a mistake. I should have started the development in RStudio.
I believe I have an issue with R not being able to find GSL, making me think the path variable is incorrect. I think this because I am able to get the given test functions for Rcpp to work, along with a few of my own test functions. However, whenever I try getting RcppGSL to work, specifically, whenever I use CTRL+SHIFT+L on my package, I get the following error:
Error in dyn.load(dllfile) : unable to load shared object '/home/max/research/qeadan/rcnetwork/src/rcnetwork.so': /home/max/research/qeadan/rcnetwork/src/rcnetwork.so: undefined symbol: gsl_vector_alloc
So, after seeing this, I looked at the following sources: Advanced R by Wickham, R Packages by Wickham, Seamless R and C++ Integration with Rcpp by Eddelbuettel, and Writing R Extensions by R Core Team (author check?) and the following SO posts (though there have been more): downloading the gsl headers into the R package is suggested; the package was borked; and the linking wasn't taking place. Nothing I've found directly addresses my issue.
Hence, I suppose my question has two parts: a) am I actually correct as to what I think the error is? and b) would someone please give me a reference that will tell me, or simply tell me, how to fix this? I'm sure the solution is simple; I just don't know how to do it, nor do I know where to look.
I've included my code, NAMESPACE, and Makevars.in folder.
Here is a version of the function I'm trying to export. I've commented out lines that require other functions I've written in C but still produce the same error I'm getting without new ones.
#include <RcppGSL.h>
#include "rootedCorrelationHeaders.h"
using namespace Rcpp;
using namespace RcppGSL;
// [[Rcpp::export]]
Rcpp::List ccm(SEXP datas, SEXP correls, double alpha){
RcppGSL::matrix<double> data = datas;
Rcpp::CharacterVector correl = correls;
//Create C/C++ types
gsl_matrix *cm1, *cm2;
//Get matrix dimensions from GSL matrix
int ROW = (int) data.nrow();
int COL = (int) data.ncol();
//Create structure to hold sorted matrices
//sm *split; //requires outside struct
//Allocate memory to data structure
//split = smAlloc(ROW, COL); //requires outside function
return Rcpp::List::create(Rcpp::Named("Comparison")= ROW,
Rcpp::Named("Correl1") = alpha,
Rcpp::Named("Correl2") = correl);
}
Here is my NAMESPACE file. But, honestly, I don't really understand it.
useDynLib(rcnetwork, .registration=TRUE)
exportPattern("^[[:alpha:]]+")
import(RcppGSL)
importFrom(Rcpp, evalCpp, sourceCpp)
Here is my Makevars.in file. Again, I don't really understand it.
# Set by configure
GSL_CFLAGS = @GSL_CFLAGS@
GSL_LIBS = @GSL_LIB@
RCPP_LDFLAGS = @RCPP_LDFLAGS@
# Combine with standard arguments for R
PKG_CPPGLAGS = $ (GSL_CFLAGS)
PKG_LIBS = $ (GSL_LIBS) $(RCPP_LDFLAGS)
Lastly, here are the relevant parts of the DESCRIPTION file (added as edit per duckmayr's comment).
License: GPL (>= 2)
LazyData: TRUE
Depends: R (>= 3.6.2)
Imports:
Rcpp,
RcppGSL,
plot.matrix
LinkingTo:
Rcpp,
RcppGSL,
plot.matrix
SystemRequirements: GNU GSL
As a final note, running the command
R.version
yields the following output:
platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 4
minor 0.0
year 2020
month 04
day 24
svn rev 78286
language R
version.string R version 4.0.0 (2020-04-24)
nickname Arbor Day
Lastly, a fix I've seen a few times on multiple posts is to use the function
compileAttributes()
In particular, people generally have to use it twice. I've done this and it doesn't change anything. It actually doesn't give any output in the console (just in case that's a red flag).
In advance, thank you so much for your help and your time.