From fb27ed319010ead62ae360d60fc62969602d16eb Mon Sep 17 00:00:00 2001 From: Dirk Eddelbuettel Date: Tue, 9 May 2017 06:23:49 -0500 Subject: [PATCH] create src/init.c for skeleton --- ChangeLog | 5 +++++ R/Rcpp.package.skeleton.R | 27 ++++++++++++++++++++------- inst/NEWS.Rd | 5 +++++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index fa635a413..19f072ee0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2017-05-09 Dirk Eddelbuettel + + * R/Rcpp.package.skeleton.R (Rcpp.package.skeleton): Under R 3.4.0, run + tools::package_native_routine_registration_skeleton to create src/init.c + 2017-05-07 Dirk Eddelbuettel * DESCRIPTION (Version, Date): Roll minor version again diff --git a/R/Rcpp.package.skeleton.R b/R/Rcpp.package.skeleton.R index 54f326b5d..95327205d 100644 --- a/R/Rcpp.package.skeleton.R +++ b/R/Rcpp.package.skeleton.R @@ -25,10 +25,10 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(), else author, email = "your@email.com", license = "GPL (>= 2)") { - + havePkgKitten <- requireNamespace("pkgKitten", quietly=TRUE) - + call <- match.call() call[[1]] <- as.name("package.skeleton") env <- parent.frame(1) @@ -102,7 +102,11 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(), lines <- readLines(NAMESPACE) ns <- file(NAMESPACE, open="w") if (! grepl("useDynLib", lines)) { - lines <- c(sprintf( "useDynLib(%s)", name), lines) + if (getRversion() >= "3.4.0") { + lines <- c(sprintf( "useDynLib(%s, .registration=TRUE)", name), lines) + } else { + lines <- c(sprintf( "useDynLib(%s)", name), lines) + } writeLines(lines, con = ns) message(" >> added useDynLib directive to NAMESPACE" ) } @@ -119,16 +123,16 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(), if (havePkgKitten) { # if pkgKitten is available, use it pkgKitten::playWithPerPackageHelpPage(name, path, maintainer, email) } else { - .playWithPerPackageHelpPage(name, path, maintainer, email) + .playWithPerPackageHelpPage(name, path, maintainer, email) } - + ## lay things out in the src directory src <- file.path(root, "src") if (!file.exists(src)) { dir.create(src) } skeleton <- system.file("skeleton", package = "Rcpp") - + if (length(cpp_files) > 0L) { for (file in cpp_files) { file.copy(file, src) @@ -181,6 +185,15 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(), message(" >> copied the example module file ") } + if (getRversion() >= "3.4.0") { + con <- file(file.path(src, "init.c"), "wt") + tools::package_native_routine_registration_skeleton(root, con=con) + close(con) + message(" >> created init.c for package registration") + } else { + message(" >> R version older than 3.4.0 detected, so NO file init.c created.") + } + lines <- readLines(package.doc <- file.path( root, "man", sprintf("%s-package.Rd", name))) lines <- sub("~~ simple examples", "%% ~~ simple examples", lines) @@ -209,7 +222,7 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(), path = ".", maintainer = "Your Name", email = "your@mail.com") { - root <- file.path(path, name) + root <- file.path(path, name) helptgt <- file.path(root, "man", sprintf( "%s-package.Rd", name)) helpsrc <- system.file("skeleton", "manual-page-stub.Rd", package="Rcpp") ## update the package description help page diff --git a/inst/NEWS.Rd b/inst/NEWS.Rd index e5994de4d..05861c1f6 100644 --- a/inst/NEWS.Rd +++ b/inst/NEWS.Rd @@ -41,6 +41,11 @@ later expects; a plugin for C++98 was added (Dirk in \ghpr{684} addressing \ghit{683}). } + \item Changes in Rcpp support functions: + \itemize{ + \item The \code{Rcpp.package.skeleton()} function now create a package + registration file provided R 3.4.0 or later is used + } } }