Note that there are some explanatory texts on larger screens.

plurals
  1. POR package that links to external C library
    primarykey
    data
    text
    <p>I have some c code that utilizes the <a href="http://igraph.sourceforge.net/index.html" rel="nofollow noreferrer">igraph</a> library. I would like to put an R wrapper around it and send it off to CRAN as an R package.</p> <p><a href="http://cran.r-project.org/web/packages/igraph/index.html" rel="nofollow noreferrer">igraph</a> already has an R port on CRAN, so it would make sense for my R package 'foo' to depend on R's igraph. Since foo uses its own C code that depends on the C igraph, how can I link my C functions to the original igraph library? I've read that this is done in a file called Makevars, but linking to an external library is very hairy. </p> <p>If this isn't possible, is it better to just copy the entire igraph source code and put the whole thing into my /src directory? The R igraph package already has a file called Makevars, but I don't understand how all the c files get built - normally in my Makefile I have something like gcc (some list of .c source files) -o, but Makevar only contains</p> <pre><code>PKG_CFLAGS=-DUSING_R -I. -Ics -Iglpk -Iglpk/amd -Iglpk/colamd \ -g -O2 -I/usr/include/libxml2 -g -O2 -I/usr/include/libxml2 -DNDEBUG \ -DPACKAGE_VERSION=\"0.6\" -DINTERNAL_ARPACK \ -DIGRAPH_THREAD_LOCAL=/**/ PKG_CXXFLAGS= -DUSING_R -DIGRAPH_THREAD_LOCAL=/**/ -DNDEBUG PKG_LIBS=-lxml2 -lz -lpthread -licucore -lm -lgmp $(FLIBS) $(LAPACK_LIBS) $(BLAS_LIBS) all: $(SHLIB) </code></pre> <p>and there is no other Makefile. In summary, how do I go about putting C code into an R package that depends on another C library, and how do I write the corresponding Makevars (or Makefile) to incorporate the C functions?</p> <p>An older question was posted <a href="https://stackoverflow.com/questions/5171516/where-is-a-good-tutorial-on-creating-an-r-package-with-c-source-code">here</a> but only seems to link to help on writing your own C code that does not depend on anything.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload