1
- # -*- tab-width: 4; -*-
2
-
3
- # Copyright (C) 2009 - 2015 Dirk Eddelbuettel and Romain Francois
1
+ # Copyright (C) 2009 - 2016 Dirk Eddelbuettel and Romain Francois
4
2
#
5
3
# This file is part of Rcpp.
6
4
#
@@ -30,74 +28,77 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(),
30
28
31
29
havePkgKitten <- requireNamespace(" pkgKitten" , quietly = TRUE )
32
30
31
+
33
32
call <- match.call()
34
33
call [[1 ]] <- as.name(" package.skeleton" )
35
34
env <- parent.frame(1 )
36
35
37
- if (! is.character(cpp_files ))
38
- stop(" 'cpp_files' must be a character vector" )
36
+ if (! is.character(cpp_files ))
37
+ stop(" 'cpp_files' must be a character vector" )
39
38
40
- if (! length(list )) {
41
- fake <- TRUE
42
- assign(" Rcpp.fake.fun" , function () {}, envir = env )
43
- if (example_code && ! isTRUE(attributes )) {
44
- assign(" rcpp_hello_world" , function () {}, envir = env )
45
- remove_hello_world <- TRUE
46
- } else {
39
+ if (! length(list )) {
40
+ fake <- TRUE
41
+ assign(" Rcpp.fake.fun" , function () {}, envir = env )
42
+ if (example_code && ! isTRUE(attributes )) {
43
+ assign(" rcpp_hello_world" , function () {}, envir = env )
44
+ remove_hello_world <- TRUE
45
+ } else {
47
46
remove_hello_world <- FALSE
48
- }
49
- } else {
47
+ }
48
+ } else {
50
49
if (example_code && ! isTRUE(attributes )) {
51
50
if (! " rcpp_hello_world" %in% list ) {
52
51
assign( " rcpp_hello_world" , function () {}, envir = env )
53
52
call [[" list" ]] <- as.call(c(as.name(" c" ),
54
53
as.list(c(" rcpp_hello_world" , list ))))
55
54
}
56
- remove_hello_world <- TRUE
57
- } else {
58
- remove_hello_world <- FALSE
59
- }
60
- fake <- FALSE
61
- }
55
+ remove_hello_world <- TRUE
56
+ } else {
57
+ remove_hello_world <- FALSE
58
+ }
59
+ fake <- FALSE
60
+ }
62
61
63
62
# # first let the traditional version do its business
64
- # # remove Rcpp specific arguments
63
+ # # remove Rcpp specific arguments
65
64
66
- call <- call [ c(1L , which(names(call ) %in% names(formals(package.skeleton )))) ]
65
+ call <- call [ c(1L , which(names(call ) %in% names(formals(package.skeleton )))) ]
67
66
68
- if (fake ) {
69
- call [[" list" ]] <- c(if (isTRUE(example_code )
67
+ if (fake ) {
68
+ call [[" list" ]] <- c(if (isTRUE(example_code )
70
69
&& ! isTRUE(attributes )) " rcpp_hello_world" , " Rcpp.fake.fun" )
71
- }
70
+ }
72
71
73
- tryCatch(eval(call , envir = env ), error = function (e ){
74
- stop(sprintf(" error while calling `package.skeleton` : %s" , conditionMessage(e )))
75
- })
72
+ tryCatch(eval(call , envir = env ), error = function (e ){
73
+ stop(sprintf(" error while calling `package.skeleton` : %s" , conditionMessage(e )))
74
+ })
76
75
77
- message(" \n Adding Rcpp settings" )
76
+ message(" \n Adding Rcpp settings" )
78
77
79
- # # now pick things up
80
- root <- file.path(path , name )
78
+ # # now pick things up
79
+ root <- file.path(path , name )
81
80
82
- # Add Rcpp to the DESCRIPTION
83
- DESCRIPTION <- file.path(root , " DESCRIPTION" )
84
- if (file.exists(DESCRIPTION )) {
85
- imports <- c(if (isTRUE(module )) " methods" ,
81
+ # Add Rcpp to the DESCRIPTION
82
+ DESCRIPTION <- file.path(root , " DESCRIPTION" )
83
+ if (file.exists(DESCRIPTION )) {
84
+ imports <- c(if (isTRUE(module )) " methods" ,
86
85
sprintf(" Rcpp (>= %s)" , packageDescription(" Rcpp" )[[" Version" ]]))
87
- x <- cbind(read.dcf(DESCRIPTION ),
86
+ x <- cbind(read.dcf(DESCRIPTION ),
88
87
" Imports" = paste(imports , collapse = " , " ),
89
88
" LinkingTo" = " Rcpp" )
90
- x [, " Author" ] <- author
91
- x [, " Maintainer" ] <- sprintf(" %s <%s>" , maintainer , email )
92
- x [, " License" ] <- license
93
- message( " >> added Imports: Rcpp" )
94
- message( " >> added LinkingTo: Rcpp" )
95
- write.dcf(x , file = DESCRIPTION )
89
+ x [, " Author" ] <- author
90
+ x [, " Maintainer" ] <- sprintf(" %s <%s>" , maintainer , email )
91
+ x [, " License" ] <- license
92
+ x [, " Title" ] <- " What the Package Does in One 'Title Case' Line"
93
+ x [, " Description" ] <- " One paragraph description of what the package does as one or more full sentences."
94
+ message( " >> added Imports: Rcpp" )
95
+ message( " >> added LinkingTo: Rcpp" )
96
+ write.dcf(x , file = DESCRIPTION )
96
97
97
- }
98
+ }
98
99
99
- # # add useDynLib and importFrom to NAMESPACE
100
- NAMESPACE <- file.path(root , " NAMESPACE" )
100
+ # # add useDynLib and importFrom to NAMESPACE
101
+ NAMESPACE <- file.path(root , " NAMESPACE" )
101
102
lines <- readLines(NAMESPACE )
102
103
ns <- file(NAMESPACE , open = " w" )
103
104
if (! grepl(" useDynLib" , lines )) {
@@ -114,98 +115,109 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(),
114
115
}
115
116
close( ns )
116
117
117
- # # update the package description help page
118
+ # # update the package description help page
118
119
if (havePkgKitten ) { # if pkgKitten is available, use it
119
120
pkgKitten :: playWithPerPackageHelpPage(name , path , maintainer , email )
120
121
} else {
121
- package_help_page <- file.path(root , " man" , sprintf( " %s-package.Rd" , name ))
122
- if (file.exists(package_help_page )) {
123
- lines <- readLines(package_help_page )
124
- lines <- gsub(" What license is it under?" , license , lines , fixed = TRUE )
125
- lines <- gsub(
" Who to complain to <[email protected] >" ,
126
- sprintf( " %s <%s>" , maintainer , email ),
127
- lines , fixed = TRUE )
128
- lines <- gsub( " Who wrote it" , author , lines , fixed = TRUE )
129
- writeLines(lines , package_help_page )
130
- }
122
+ .playWithPerPackageHelpPage(name , path , maintainer , email )
131
123
}
132
124
133
- # # lay things out in the src directory
134
- src <- file.path(root , " src" )
135
- if (! file.exists(src )) {
136
- dir.create(src )
137
- }
138
- skeleton <- system.file(" skeleton" , package = " Rcpp" )
139
-
140
- if (length(cpp_files ) > 0L ) {
141
- for (file in cpp_files ) {
142
- file.copy(file , src )
143
- message(" >> copied " , file , " to src directory" )
144
- }
145
- compileAttributes(root )
146
- }
147
-
148
- if (example_code ) {
149
- if (isTRUE(attributes )) {
150
- file.copy(file.path( skeleton , " rcpp_hello_world_attributes.cpp" ),
125
+ # # lay things out in the src directory
126
+ src <- file.path(root , " src" )
127
+ if (! file.exists(src )) {
128
+ dir.create(src )
129
+ }
130
+ skeleton <- system.file(" skeleton" , package = " Rcpp" )
131
+
132
+ if (length(cpp_files ) > 0L ) {
133
+ for (file in cpp_files ) {
134
+ file.copy(file , src )
135
+ message(" >> copied " , file , " to src directory" )
136
+ }
137
+ compileAttributes(root )
138
+ }
139
+
140
+ if (example_code ) {
141
+ if (isTRUE(attributes )) {
142
+ file.copy(file.path( skeleton , " rcpp_hello_world_attributes.cpp" ),
151
143
file.path( src , " rcpp_hello_world.cpp" ))
152
- message(" >> added example src file using Rcpp attributes" )
153
- compileAttributes(root )
154
- message(" >> compiled Rcpp attributes" )
155
- } else {
156
- header <- readLines(file.path(skeleton , " rcpp_hello_world.h" ))
157
- header <- gsub(" @PKG@" , name , header , fixed = TRUE )
158
- writeLines(header , file.path(src , " rcpp_hello_world.h" ))
159
- message(" >> added example header file using Rcpp classes" )
160
-
161
- file.copy(file.path(skeleton , " rcpp_hello_world.cpp" ), src )
162
- message(" >> added example src file using Rcpp classes" )
163
-
164
- rcode <- readLines(file.path( skeleton , " rcpp_hello_world.R" ))
165
- rcode <- gsub(" @PKG@" , name , rcode , fixed = TRUE )
166
- writeLines( rcode , file.path( root , " R" , " rcpp_hello_world.R" ))
167
- message(" >> added example R file calling the C++ example" )
168
- }
169
-
170
- hello.Rd <- file.path(root , " man" , " rcpp_hello_world.Rd" )
171
- unlink(hello.Rd )
172
- file.copy(system.file(" skeleton" , " rcpp_hello_world.Rd" , package = " Rcpp" ), hello.Rd )
173
- message( " >> added Rd file for rcpp_hello_world" )
174
- }
175
-
176
- if (isTRUE(module )) {
177
- file.copy(system.file(" skeleton" , " rcpp_module.cpp" , package = " Rcpp" ),
144
+ message(" >> added example src file using Rcpp attributes" )
145
+ compileAttributes(root )
146
+ message(" >> compiled Rcpp attributes" )
147
+ } else {
148
+ header <- readLines(file.path(skeleton , " rcpp_hello_world.h" ))
149
+ header <- gsub(" @PKG@" , name , header , fixed = TRUE )
150
+ writeLines(header , file.path(src , " rcpp_hello_world.h" ))
151
+ message(" >> added example header file using Rcpp classes" )
152
+
153
+ file.copy(file.path(skeleton , " rcpp_hello_world.cpp" ), src )
154
+ message(" >> added example src file using Rcpp classes" )
155
+
156
+ rcode <- readLines(file.path( skeleton , " rcpp_hello_world.R" ))
157
+ rcode <- gsub(" @PKG@" , name , rcode , fixed = TRUE )
158
+ writeLines( rcode , file.path( root , " R" , " rcpp_hello_world.R" ))
159
+ message(" >> added example R file calling the C++ example" )
160
+ }
161
+
162
+ hello.Rd <- file.path(root , " man" , " rcpp_hello_world.Rd" )
163
+ unlink(hello.Rd )
164
+ file.copy(system.file(" skeleton" , " rcpp_hello_world.Rd" , package = " Rcpp" ), hello.Rd )
165
+ message( " >> added Rd file for rcpp_hello_world" )
166
+ }
167
+
168
+ if (isTRUE(module )) {
169
+ file.copy(system.file(" skeleton" , " rcpp_module.cpp" , package = " Rcpp" ),
178
170
file.path(root , " src" ))
179
- file.copy(system.file(" skeleton" , " Num.cpp" , package = " Rcpp" ),
171
+ file.copy(system.file(" skeleton" , " Num.cpp" , package = " Rcpp" ),
180
172
file.path(root , " src" ))
181
- file.copy(system.file(" skeleton" , " stdVector.cpp" , package = " Rcpp" ),
173
+ file.copy(system.file(" skeleton" , " stdVector.cpp" , package = " Rcpp" ),
182
174
file.path(root , " src" ))
183
- file.copy(system.file(" skeleton" , " zzz.R" , package = " Rcpp" ),
175
+ file.copy(system.file(" skeleton" , " zzz.R" , package = " Rcpp" ),
184
176
file.path(root , " R" ))
185
- file.copy(system.file(" skeleton" , " Rcpp_modules_examples.Rd" , package = " Rcpp" ),
177
+ file.copy(system.file(" skeleton" , " Rcpp_modules_examples.Rd" , package = " Rcpp" ),
186
178
file.path(root , " man" ))
187
- message(" >> copied the example module file " )
188
- }
179
+ message(" >> copied the example module file " )
180
+ }
181
+
182
+ lines <- readLines(package.doc <- file.path( root , " man" , sprintf(" %s-package.Rd" , name )))
183
+ lines <- sub(" ~~ simple examples" , " %% ~~ simple examples" , lines )
189
184
190
- lines <- readLines(package.doc <- file.path( root , " man" , sprintf(" %s-package.Rd" , name )))
191
- lines <- sub(" ~~ simple examples" , " %% ~~ simple examples" , lines )
185
+ lines <- lines [! grepl(" ~~ package title" , lines )]
186
+ lines <- lines [! grepl(" ~~ The author and" , lines )]
187
+ lines <- sub(" Who wrote it" , author , lines )
188
+ lines <- sub(" Who to complain to.*" , sprintf(" %s <%s>" , maintainer , email ), lines )
192
189
193
- lines <- lines [! grepl(" ~~ package title" , lines )]
194
- lines <- lines [! grepl(" ~~ The author and" , lines )]
195
- lines <- sub(" Who wrote it" , author , lines )
196
- lines <- sub(" Who to complain to.*" , sprintf(" %s <%s>" , maintainer , email ), lines )
190
+ writeLines(lines , package.doc )
197
191
198
- writeLines(lines , package.doc )
192
+ if (fake ) {
193
+ rm(" Rcpp.fake.fun" , envir = env )
194
+ unlink(file.path(root , " R" , " Rcpp.fake.fun.R" ))
195
+ unlink(file.path(root , " man" , " Rcpp.fake.fun.Rd" ))
196
+ }
199
197
200
- if (fake ) {
201
- rm(" Rcpp.fake.fun" , envir = env )
202
- unlink(file.path(root , " R" , " Rcpp.fake.fun.R" ))
203
- unlink(file.path(root , " man" , " Rcpp.fake.fun.Rd" ))
204
- }
198
+ if (isTRUE(remove_hello_world )) {
199
+ rm(" rcpp_hello_world" , envir = env )
200
+ }
205
201
206
- if (isTRUE(remove_hello_world )) {
207
- rm(" rcpp_hello_world" , envir = env )
208
- }
202
+ invisible (NULL )
203
+ }
209
204
210
- invisible (NULL )
205
+ # # Borrowed with love from pkgKitten, and modified slightly
206
+ .playWithPerPackageHelpPage <- function (name = " anRpackage" ,
207
+ path = " ." ,
208
+ maintainer = " Your Name" ,
209
+
210
+ root <- file.path(path , name )
211
+ helptgt <- file.path(root , " man" , sprintf( " %s-package.Rd" , name ))
212
+ helpsrc <- system.file(" skeleton" , " manual-page-stub.Rd" , package = " Rcpp" )
213
+ # # update the package description help page
214
+ if (file.exists(helpsrc )) {
215
+ lines <- readLines(helpsrc )
216
+ lines <- gsub(" __placeholder__" , name , lines , fixed = TRUE )
217
+ lines <- gsub(
" Who to complain to <[email protected] >" ,
218
+ sprintf( " %s <%s>" , maintainer , email ),
219
+ lines , fixed = TRUE )
220
+ writeLines(lines , helptgt )
221
+ }
222
+ invisible (NULL )
211
223
}
0 commit comments