Skip to content

Commit 4e0f79c

Browse files
authored
create src/init.c for skeleton (#692)
1 parent c536419 commit 4e0f79c

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2017-05-09 Dirk Eddelbuettel <[email protected]>
2+
3+
* R/Rcpp.package.skeleton.R (Rcpp.package.skeleton): Under R 3.4.0, run
4+
tools::package_native_routine_registration_skeleton to create src/init.c
5+
16
2017-05-07 Dirk Eddelbuettel <[email protected]>
27

38
* DESCRIPTION (Version, Date): Roll minor version again

R/Rcpp.package.skeleton.R

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(),
2525
else author,
2626
email = "[email protected]",
2727
license = "GPL (>= 2)") {
28-
28+
2929
havePkgKitten <- requireNamespace("pkgKitten", quietly=TRUE)
3030

31-
31+
3232
call <- match.call()
3333
call[[1]] <- as.name("package.skeleton")
3434
env <- parent.frame(1)
@@ -102,7 +102,11 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(),
102102
lines <- readLines(NAMESPACE)
103103
ns <- file(NAMESPACE, open="w")
104104
if (! grepl("useDynLib", lines)) {
105-
lines <- c(sprintf( "useDynLib(%s)", name), lines)
105+
if (getRversion() >= "3.4.0") {
106+
lines <- c(sprintf( "useDynLib(%s, .registration=TRUE)", name), lines)
107+
} else {
108+
lines <- c(sprintf( "useDynLib(%s)", name), lines)
109+
}
106110
writeLines(lines, con = ns)
107111
message(" >> added useDynLib directive to NAMESPACE" )
108112
}
@@ -119,16 +123,16 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(),
119123
if (havePkgKitten) { # if pkgKitten is available, use it
120124
pkgKitten::playWithPerPackageHelpPage(name, path, maintainer, email)
121125
} else {
122-
.playWithPerPackageHelpPage(name, path, maintainer, email)
126+
.playWithPerPackageHelpPage(name, path, maintainer, email)
123127
}
124-
128+
125129
## lay things out in the src directory
126130
src <- file.path(root, "src")
127131
if (!file.exists(src)) {
128132
dir.create(src)
129133
}
130134
skeleton <- system.file("skeleton", package = "Rcpp")
131-
135+
132136
if (length(cpp_files) > 0L) {
133137
for (file in cpp_files) {
134138
file.copy(file, src)
@@ -181,6 +185,15 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(),
181185
message(" >> copied the example module file ")
182186
}
183187

188+
if (getRversion() >= "3.4.0") {
189+
con <- file(file.path(src, "init.c"), "wt")
190+
tools::package_native_routine_registration_skeleton(root, con=con)
191+
close(con)
192+
message(" >> created init.c for package registration")
193+
} else {
194+
message(" >> R version older than 3.4.0 detected, so NO file init.c created.")
195+
}
196+
184197
lines <- readLines(package.doc <- file.path( root, "man", sprintf("%s-package.Rd", name)))
185198
lines <- sub("~~ simple examples", "%% ~~ simple examples", lines)
186199

@@ -209,7 +222,7 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(),
209222
path = ".",
210223
maintainer = "Your Name",
211224
email = "[email protected]") {
212-
root <- file.path(path, name)
225+
root <- file.path(path, name)
213226
helptgt <- file.path(root, "man", sprintf( "%s-package.Rd", name))
214227
helpsrc <- system.file("skeleton", "manual-page-stub.Rd", package="Rcpp")
215228
## update the package description help page

inst/NEWS.Rd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
later expects; a plugin for C++98 was added (Dirk in \ghpr{684} addressing
4545
\ghit{683}).
4646
}
47+
\item Changes in Rcpp support functions:
48+
\itemize{
49+
\item The \code{Rcpp.package.skeleton()} function now create a package
50+
registration file provided R 3.4.0 or later is used
51+
}
4752
}
4853
}
4954

0 commit comments

Comments
 (0)