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
#
@@ -34,70 +32,72 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(),
34
32
call [[1 ]] <- as.name(" package.skeleton" )
35
33
env <- parent.frame(1 )
36
34
37
- if (! is.character(cpp_files ))
38
- stop(" 'cpp_files' must be a character vector" )
35
+ if (! is.character(cpp_files ))
36
+ stop(" 'cpp_files' must be a character vector" )
39
37
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 {
38
+ if (! length(list )) {
39
+ fake <- TRUE
40
+ assign(" Rcpp.fake.fun" , function () {}, envir = env )
41
+ if (example_code && ! isTRUE(attributes )) {
42
+ assign(" rcpp_hello_world" , function () {}, envir = env )
43
+ remove_hello_world <- TRUE
44
+ } else {
47
45
remove_hello_world <- FALSE
48
- }
49
- } else {
46
+ }
47
+ } else {
50
48
if (example_code && ! isTRUE(attributes )) {
51
49
if (! " rcpp_hello_world" %in% list ) {
52
50
assign( " rcpp_hello_world" , function () {}, envir = env )
53
51
call [[" list" ]] <- as.call(c(as.name(" c" ),
54
52
as.list(c(" rcpp_hello_world" , list ))))
55
53
}
56
- remove_hello_world <- TRUE
57
- } else {
58
- remove_hello_world <- FALSE
59
- }
60
- fake <- FALSE
61
- }
54
+ remove_hello_world <- TRUE
55
+ } else {
56
+ remove_hello_world <- FALSE
57
+ }
58
+ fake <- FALSE
59
+ }
62
60
63
61
# # first let the traditional version do its business
64
- # # remove Rcpp specific arguments
62
+ # # remove Rcpp specific arguments
65
63
66
- call <- call [ c(1L , which(names(call ) %in% names(formals(package.skeleton )))) ]
64
+ call <- call [ c(1L , which(names(call ) %in% names(formals(package.skeleton )))) ]
67
65
68
- if (fake ) {
69
- call [[" list" ]] <- c(if (isTRUE(example_code )
66
+ if (fake ) {
67
+ call [[" list" ]] <- c(if (isTRUE(example_code )
70
68
&& ! isTRUE(attributes )) " rcpp_hello_world" , " Rcpp.fake.fun" )
71
- }
69
+ }
72
70
73
- tryCatch(eval(call , envir = env ), error = function (e ){
74
- stop(sprintf(" error while calling `package.skeleton` : %s" , conditionMessage(e )))
75
- })
71
+ tryCatch(eval(call , envir = env ), error = function (e ){
72
+ stop(sprintf(" error while calling `package.skeleton` : %s" , conditionMessage(e )))
73
+ })
76
74
77
- message(" \n Adding Rcpp settings" )
75
+ message(" \n Adding Rcpp settings" )
78
76
79
- # # now pick things up
80
- root <- file.path(path , name )
77
+ # # now pick things up
78
+ root <- file.path(path , name )
81
79
82
- # Add Rcpp to the DESCRIPTION
83
- DESCRIPTION <- file.path(root , " DESCRIPTION" )
84
- if (file.exists(DESCRIPTION )) {
85
- imports <- c(if (isTRUE(module )) " methods" ,
80
+ # Add Rcpp to the DESCRIPTION
81
+ DESCRIPTION <- file.path(root , " DESCRIPTION" )
82
+ if (file.exists(DESCRIPTION )) {
83
+ imports <- c(if (isTRUE(module )) " methods" ,
86
84
sprintf(" Rcpp (>= %s)" , packageDescription(" Rcpp" )[[" Version" ]]))
87
- x <- cbind(read.dcf(DESCRIPTION ),
85
+ x <- cbind(read.dcf(DESCRIPTION ),
88
86
" Imports" = paste(imports , collapse = " , " ),
89
87
" 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 )
88
+ x [, " Author" ] <- author
89
+ x [, " Maintainer" ] <- sprintf(" %s <%s>" , maintainer , email )
90
+ x [, " License" ] <- license
91
+ x [, " Title" ] <- " What the Package Does in One 'Title Case' Line"
92
+ x [, " Description" ] <- " One paragraph description of what the package does as one or more full sentences."
93
+ message( " >> added Imports: Rcpp" )
94
+ message( " >> added LinkingTo: Rcpp" )
95
+ write.dcf(x , file = DESCRIPTION )
96
96
97
- }
97
+ }
98
98
99
- # # add useDynLib and importFrom to NAMESPACE
100
- NAMESPACE <- file.path(root , " NAMESPACE" )
99
+ # # add useDynLib and importFrom to NAMESPACE
100
+ NAMESPACE <- file.path(root , " NAMESPACE" )
101
101
lines <- readLines(NAMESPACE )
102
102
ns <- file(NAMESPACE , open = " w" )
103
103
if (! grepl(" useDynLib" , lines )) {
@@ -114,7 +114,7 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(),
114
114
}
115
115
close( ns )
116
116
117
- # # update the package description help page
117
+ # # update the package description help page
118
118
if (havePkgKitten ) { # if pkgKitten is available, use it
119
119
pkgKitten :: playWithPerPackageHelpPage(name , path , maintainer , email )
120
120
} else {
@@ -130,82 +130,82 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(),
130
130
}
131
131
}
132
132
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" ),
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" ),
151
151
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" ),
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" ),
178
178
file.path(root , " src" ))
179
- file.copy(system.file(" skeleton" , " Num.cpp" , package = " Rcpp" ),
179
+ file.copy(system.file(" skeleton" , " Num.cpp" , package = " Rcpp" ),
180
180
file.path(root , " src" ))
181
- file.copy(system.file(" skeleton" , " stdVector.cpp" , package = " Rcpp" ),
181
+ file.copy(system.file(" skeleton" , " stdVector.cpp" , package = " Rcpp" ),
182
182
file.path(root , " src" ))
183
- file.copy(system.file(" skeleton" , " zzz.R" , package = " Rcpp" ),
183
+ file.copy(system.file(" skeleton" , " zzz.R" , package = " Rcpp" ),
184
184
file.path(root , " R" ))
185
- file.copy(system.file(" skeleton" , " Rcpp_modules_examples.Rd" , package = " Rcpp" ),
185
+ file.copy(system.file(" skeleton" , " Rcpp_modules_examples.Rd" , package = " Rcpp" ),
186
186
file.path(root , " man" ))
187
- message(" >> copied the example module file " )
188
- }
187
+ message(" >> copied the example module file " )
188
+ }
189
189
190
- lines <- readLines(package.doc <- file.path( root , " man" , sprintf(" %s-package.Rd" , name )))
191
- lines <- sub(" ~~ simple examples" , " %% ~~ simple examples" , lines )
190
+ lines <- readLines(package.doc <- file.path( root , " man" , sprintf(" %s-package.Rd" , name )))
191
+ lines <- sub(" ~~ simple examples" , " %% ~~ simple examples" , lines )
192
192
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 )
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 )
197
197
198
- writeLines(lines , package.doc )
198
+ writeLines(lines , package.doc )
199
199
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
- }
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
+ }
205
205
206
- if (isTRUE(remove_hello_world )) {
207
- rm(" rcpp_hello_world" , envir = env )
208
- }
206
+ if (isTRUE(remove_hello_world )) {
207
+ rm(" rcpp_hello_world" , envir = env )
208
+ }
209
209
210
- invisible (NULL )
210
+ invisible (NULL )
211
211
}
0 commit comments