Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd635089

Browse files
committed
Merge pull request#471 from RcppCore/feature/update-pkg-skeleton
update Rcpp.package.skeleton()
2 parentsb58bf98 +5c364c1 commitd635089

File tree

4 files changed

+189
-122
lines changed

4 files changed

+189
-122
lines changed

‎ChangeLog‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
2016-05-11 Dirk Eddelbuettel <edd@debian.org>
2+
3+
* R/Rcpp.package.skeleton.R: Modified to create a package without notes,
4+
warnings, or error even pkgKitten is not available
5+
6+
* R/Rcpp.package.skeleton.R (.playWithPerPackageHelpPage): Added new
7+
helper function to be used when pkgKitten is not available
8+
* inst/skeleton/manual-page-stub.Rd: Stub for per-package help page used
9+
when pkgKitten is not available
10+
11+
2016-05-10 Dirk Eddelbuettel <edd@debian.org>
12+
13+
* R/Rcpp.package.skeleton.R: Also correct Title: and Description: to
14+
satisfy R CMD check in R-release and (current) R-devel
15+
116
2016-05-08 Dirk Eddelbuettel <edd@debian.org>
217

318
* inst/unitTests/cpp/Matrix.cpp: Made four scalar/matrix tests less

‎R/Rcpp.package.skeleton.R‎

Lines changed: 134 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
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
42
#
53
# This file is part of Rcpp.
64
#
@@ -30,74 +28,77 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(),
3028

3129
havePkgKitten<- requireNamespace("pkgKitten",quietly=TRUE)
3230

31+
3332
call<- match.call()
3433
call[[1]]<- as.name("package.skeleton")
3534
env<- parent.frame(1)
3635

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")
3938

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 {
4746
remove_hello_world<-FALSE
48-
}
49-
}else {
47+
}
48+
}else {
5049
if (example_code&&!isTRUE(attributes)) {
5150
if (!"rcpp_hello_world"%in%list) {
5251
assign("rcpp_hello_world",function() {},envir=env)
5352
call[["list"]]<- as.call(c(as.name("c"),
5453
as.list(c("rcpp_hello_world",list))))
5554
}
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+
}
6261

6362
## first let the traditional version do its business
64-
## remove Rcpp specific arguments
63+
## remove Rcpp specific arguments
6564

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)))) ]
6766

68-
if (fake) {
69-
call[["list"]]<- c(if(isTRUE(example_code)
67+
if (fake) {
68+
call[["list"]]<- c(if(isTRUE(example_code)
7069
&&!isTRUE(attributes))"rcpp_hello_world","Rcpp.fake.fun")
71-
}
70+
}
7271

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+
})
7675

77-
message("\nAdding Rcpp settings")
76+
message("\nAdding Rcpp settings")
7877

79-
## now pick things up
80-
root<- file.path(path,name)
78+
## now pick things up
79+
root<- file.path(path,name)
8180

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",
8685
sprintf("Rcpp (>= %s)", packageDescription("Rcpp")[["Version"]]))
87-
x<- cbind(read.dcf(DESCRIPTION),
86+
x<- cbind(read.dcf(DESCRIPTION),
8887
"Imports"= paste(imports,collapse=","),
8988
"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)
9697

97-
}
98+
}
9899

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")
101102
lines<- readLines(NAMESPACE)
102103
ns<- file(NAMESPACE,open="w")
103104
if (! grepl("useDynLib",lines)) {
@@ -114,98 +115,109 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(),
114115
}
115116
close(ns )
116117

117-
## update the package description help page
118+
## update the package description help page
118119
if (havePkgKitten) {# if pkgKitten is available, use it
119120
pkgKitten::playWithPerPackageHelpPage(name,path,maintainer,email)
120121
}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 <yourfault@somewhere.net>",
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)
131123
}
132124

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 (fileincpp_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 (fileincpp_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"),
151143
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"),
178170
file.path(root,"src"))
179-
file.copy(system.file("skeleton","Num.cpp",package="Rcpp"),
171+
file.copy(system.file("skeleton","Num.cpp",package="Rcpp"),
180172
file.path(root,"src"))
181-
file.copy(system.file("skeleton","stdVector.cpp",package="Rcpp"),
173+
file.copy(system.file("skeleton","stdVector.cpp",package="Rcpp"),
182174
file.path(root,"src"))
183-
file.copy(system.file("skeleton","zzz.R",package="Rcpp"),
175+
file.copy(system.file("skeleton","zzz.R",package="Rcpp"),
184176
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"),
186178
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)
189184

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)
192189

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)
197191

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+
}
199197

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+
}
205201

206-
if (isTRUE(remove_hello_world)) {
207-
rm("rcpp_hello_world",envir=env)
208-
}
202+
invisible(NULL)
203+
}
209204

210-
invisible(NULL)
205+
## Borrowed with love from pkgKitten, and modified slightly
206+
.playWithPerPackageHelpPage<-function(name="anRpackage",
207+
path=".",
208+
maintainer="Your Name",
209+
email="your@mail.com") {
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 <yourfault@somewhere.net>",
218+
sprintf("%s <%s>",maintainer,email),
219+
lines,fixed=TRUE)
220+
writeLines(lines,helptgt)
221+
}
222+
invisible(NULL)
211223
}

‎inst/NEWS.Rd‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
\item The (older) \code{loadRcppModules()}isnowdeprecatedinfavourof
2424
\code{loadModule()}introducedaroundR2.15.1andRcpp0.9.11.
2525
}
26+
\itemChangesinRcppsupportfunctions:
27+
\itemize{
28+
\itemThe \code{Rcpp.package.skeleton()}functionwasagainupdatedin
29+
ordertocreatea \code{DESCRIPTION}filewhichpasses \code{RCMDcheck}
30+
withoutnotes.warnings,orerrorunderR-releaseandR-devel.
31+
}
2632
}
2733
}
2834

‎inst/skeleton/manual-page-stub.Rd‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
\name{__placeholder__-package}
2+
\alias{__placeholder__-package}
3+
\alias{__placeholder__}
4+
\docType{package}
5+
\title{
6+
Ashorttitlelinedescribingwhatthepackagedoes
7+
}
8+
\description{
9+
Amoredetaileddescriptionofwhatthepackagedoes.Alength
10+
ofaboutonetofivelinesisrecommended.
11+
}
12+
\details{
13+
Thissectionshouldprovideamoredetailedoverviewofhowtousethe
14+
package,includingthemostimportantfunctions.
15+
}
16+
\author{
17+
Whowroteit,emailoptional.
18+
19+
Maintainer:Whotocomplainto<yourfault@somewhere.net>
20+
}
21+
\references{
22+
Thisoptionalsectioncancontainliteratureorotherreferencesfor
23+
backgroundinformation.
24+
}
25+
\keyword{package }
26+
\seealso{
27+
Optionallinkstoothermanpages
28+
}
29+
\examples{
30+
\dontrun{
31+
## Optional simple examples of the most important functions
32+
## These can be in \dontrun{} and \donttest{} blocks.
33+
}
34+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp