http://www.keittlab.org/
On Thu, Mar 30, 2017 at 4:00 PM, Dirk Eddelbuettel <e...@debian.org> wrote: > > The function creating the src/init.c file was already written by Brian > Ripley > and Kurt Hornik. > Here's another: contents = readLines("src/RcppExports.cpp") protos = grep("^RcppExport", contents, value = TRUE) funcs = sub("^RcppExport SEXP (.*)\\(.*", "\\1", protos) nargs = sapply(gregexpr("\\<SEXP\\>", protos), length) - 1 gen_call_method = function(fname, nargs) { if (is.na(fname) || is.na(nargs)) return("\t{NULL, NULL, 0}};") return(paste0('\t{"', fname, '", (DL_FUNC) &', fname, ', ', nargs, '}')) } funcs = c(funcs, NA); nargs = c(nargs, NA) cms = lapply(1:length(funcs), function(i) gen_call_method(funcs[i], nargs[i])) cat("#include <R.h>\n", file = "src/init.c") cat("#include <Rinternals.h>\n", file = "src/init.c", append = TRUE) cat("#include <R_ext/Rdynload.h>\n\n", file = "src/init.c", append = TRUE) protos = paste0("\n\t*", funcs[-length(funcs)], collapse = ",") cat(paste0("extern void ", protos, ";\n\n"), file = "src/init.c", append = TRUE) cat("R_CallMethodDef callMethods[] = {\n", file = "src/init.c", append = TRUE) cat(paste(cms, collapse = ",\n"), file = "src/init.c", append = TRUE) cat("\n\nvoid\nR_init_myLib(DllInfo *info)\n{\n", file = "src/init.c", append = TRUE) cat("\tR_registerRoutines(info, NULL, callMethods, NULL, NULL);\n", file = "src/init.c", append = TRUE) cat("\tR_useDynamicSymbols(info, FALSE);\n}", file = "src/init.c", append = TRUE) I added it to my 'configure' script. THK > > Dirk > > -- > http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org >
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel