@@ -25,10 +25,10 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(),
2525 else author ,
26262727 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" ,
211224212- 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
0 commit comments