<div dir="ltr"><br><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><a href="http://www.keittlab.org/" target="_blank">http://www.keittlab.org/</a></div></div></div>
<br><div class="gmail_quote">On Thu, Mar 30, 2017 at 4:00 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
The function creating the src/init.c file was already written by Brian Ripley<br>
and Kurt Hornik.<br></blockquote><div><br></div><div>Here's another:</div><div><br></div><div>contents = readLines("src/RcppExports.cpp")</div><div>protos = grep("^RcppExport", contents, value = TRUE)</div><div>funcs = sub("^RcppExport SEXP (.*)\\(.*", "\\1", protos)</div><div>nargs = sapply(gregexpr("\\<SEXP\\>", protos), length) - 1</div><div>gen_call_method = function(fname, nargs)</div><div>{</div><div> if (<a href="http://is.na">is.na</a>(fname) || <a href="http://is.na">is.na</a>(nargs))</div><div> return("\t{NULL, NULL, 0}};")</div><div> return(paste0('\t{"', fname, '", (DL_FUNC) &',</div><div> fname, ', ', nargs, '}'))</div><div>}</div><div>funcs = c(funcs, NA); nargs = c(nargs, NA)</div><div>cms = lapply(1:length(funcs), function(i) gen_call_method(funcs[i], nargs[i]))</div><div> </div><div>cat("#include <R.h>\n", file = "src/init.c")</div><div>cat("#include <Rinternals.h>\n", file = "src/init.c", append = TRUE)</div><div>cat("#include <R_ext/Rdynload.h>\n\n", file = "src/init.c", append = TRUE)</div><div><br></div><div>protos = paste0("\n\t*", funcs[-length(funcs)], collapse = ",")</div><div>cat(paste0("extern void ", protos, ";\n\n"), file = "src/init.c", append = TRUE)</div><div><br></div><div>cat("R_CallMethodDef callMethods[] = {\n", file = "src/init.c", append = TRUE)</div><div>cat(paste(cms, collapse = ",\n"), file = "src/init.c", append = TRUE)</div><div>cat("\n\nvoid\nR_init_myLib(DllInfo *info)\n{\n", file = "src/init.c", append = TRUE)</div><div>cat("\tR_registerRoutines(info, NULL, callMethods, NULL, NULL);\n", file = "src/init.c", append = TRUE)</div><div>cat("\tR_useDynamicSymbols(info, FALSE);\n}", file = "src/init.c", append = TRUE)</div><div><br></div><div>I added it to my 'configure' script.</div><div><br></div><div>THK</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span class="gmail-HOEnZb"><font color="#888888"><br>
Dirk<br>
<br>
--<br>
<a href="http://dirk.eddelbuettel.com" rel="noreferrer" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a><br>
</font></span></blockquote></div><br></div></div>