I'm not sure exactly what you want to do but it seems you are going
about it in an overly complicated way. If you are going to build a
package you just need to put a NAMESPACE file at the top level and
include a useDynLib specification or write a short R function called
.First.Lib that calls library.dynam and include it in the R
subdirectory. Typically this function is simply
.First.lib = function(lib, pkg) {
library.dynam(pkg, pkg, lib)
}
but it can do other initializations.
After that you just put the source for myincr in the src subdirectory,
compile and load the package, then call the function as
.Call("myincr", x, PACKAGE="myPackageName")
Pat Gunn <pgunn at cs.cmu.edu> writes:
> Hello,
> I need a bit of handholding with R, specifically, with writing
> packages for it. I'm a systems programmer, and am, on the request
> of several users of our software, working on generating R interfaces.
> For starters, I've written the following R function (which compiles):
>
> SEXP myincr(SEXP Rinput)
> { // Returns input integer incremented by one
> int input;
> SEXP returner;
>
> PROTECT(Rinput = AS_NUMERIC(Rinput));
>
> input = * INTEGER(Rinput);
> input++;
> PROTECT(returner = NEW_INTEGER(input));
> Rprintf("Hey there\n");
> return returner;
> }
>
> I've made this into a package, by dropping it into a stub directory
> along with something called init.c:
>
> #include "areone.h"
> #include <R_ext/Rdynload.h>
> #include <Rinternals.h>
>
> R_NativePrimitiveArgType myincr_t[1] = {INTSXP};
>
> static const R_CMethodDef cMethods[] > {
> {"myincr", (DL_FUNC) &myincr, 1, myincr_t}
> };
>
> void R_init_myincr(DllInfo* dll)
> {
> R_registerRoutines(dll, cMethods, NULL, NULL, NULL);
> }
>
> R is happy to install this for me, but after doing a library(myincr),
> the function doesn't seem to be available, so I presume I'm missing
> something. Does R normally call, at library load, R_init_$MODULENAME() ?
>
>
> My other question is.. our software produces data structures (we call
datsets)
> which resemble limited database tables, and I'd like some advice on
exposing
> them to R -- columns, in our scheme, either hold doubles or strings,
> the columns have names, and we need the ability to export these into
> appropriate R structures as well as populate them from R. I notice that
> the R DBI, at least as according to its documentation, uses the database
> to hold the data (presumably in temporary tables) and returns parts of it
> as requested, via R functions. I could use a static global pointer (in C)
into a
> storage space of datsets, and write bridge functions exporting them as R
arrays,
> or I could attempt to find an appropriate native format and export to it..
> any advice?
>
> It might be worth mentioning that all of the code to do this will
> eventually be auto-generated -- we already have code to do this for C
> that doesn't need to expose people linking our code to all of our
> custom structures and stuff.
>
> --
> Pat Gunn
> Research/Systems Programmer, Auton Group, CMU
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
--
Douglas Bates bates at stat.wisc.edu
Statistics Department 608/262-2598
University of Wisconsin - Madison http://www.stat.wisc.edu/~bates/