PoonLab / Kaphi

Kernel-embedded ABC-SMC for phylodynamic inference
GNU Affero General Public License v3.0
4 stars 2 forks source link

Pass an igraph object from R to C #5

Closed ArtPoon closed 8 years ago

ArtPoon commented 8 years ago

Writing a simple bit of C code test.c and an R script test.R that will create an igraph object from a phylogeny and then pass it to C. Working off the rinterface.c code from rigraph as a template. There seem to be some versioning issues with Rosemary's fork of igraph and function calls in rinterface.c that I've temporarily resolved by stripping out the offending functions in the latter.

ArtPoon commented 8 years ago

Right now the build script is not working:

Undefined symbols for architecture x86_64:
  "_R_SEXP_to_igraph", referenced from:
      _R_igraph_test in test-f09788.o
  "_Rf_allocVector", referenced from:
      _R_igraph_test in test-f09788.o
  "_Rf_protect", referenced from:
      _R_igraph_test in test-f09788.o
  "_Rf_unprotect", referenced from:
      _R_igraph_test in test-f09788.o
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ArtPoon commented 8 years ago

Duh, needed to set a -c flag or specify a main() function in test.c. Now need to compile this in a way that we can call it from R.

ArtPoon commented 8 years ago

Still having trouble:

Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Kaphi/libs/Kaphi.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Kaphi/libs/Kaphi.so, 6): Symbol not found: _igraph_destroy
  Referenced from: /Library/Frameworks/R.framework/Versions/3.2/Resources/library/Kaphi/libs/Kaphi.so

StackOverflow suggests that I've forgotten to compile with the igraph library.

ArtPoon commented 8 years ago

Okay, I've given up on compiling igraph and am using MacPorts for now (see issue #3).
The above error has been resolved, but we're onto another one:

Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Kaphi/libs/Kaphi.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.2/Resources/library/Kaphi/libs/Kaphi.so, 6): Symbol not found: _R_igraph_add_env
ArtPoon commented 8 years ago

Well, I've gutted rinterface.c of all functions that gave complaints at compilation, and this now appears to compile. Hopefully we now have a basis for testing code.

ArtPoon commented 8 years ago

Making sure the igraph and rigraph sources are the same version helps avoid the errors that arose in compiling. I'm using 0.7.1 for both. However, I'm still running into this problem:

** preparing package for lazy loading
Error in .Call("treekernel", graph, PACKAGE = "Kaphi") : 
  "treekernel" not available for .Call() for package "Kaphi"
Error : unable to load R code in package ‘Kaphi’
ERROR: lazy loading failed for package ‘Kaphi’

Removing the .Call() to treekernel in the test script test.R makes it possible to install the package, but of course this is not very useful.

ArtPoon commented 8 years ago

This is largely an issue with NAMESPACE:

  1. We apparently cannot execute a function defined in an R script within the package.
  2. The name of the R function within the script must be placed in an export statement in the NAMESPACE file.
ArtPoon commented 8 years ago

Close by 21ba93f07801ecce9bf9e3e963aa2f347249f86a