[Rcpp-devel] Question regarding new pacakge registration requirements

Tim Keitt tkeitt at utexas.edu
Fri Mar 31 04:15:47 CEST 2017


http://www.keittlab.org/

On Thu, Mar 30, 2017 at 4:00 PM, Dirk Eddelbuettel <edd at 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 | edd at debian.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20170330/dbe8c68c/attachment.html>


More information about the Rcpp-devel mailing list