Skip to content

Commit 50d8ad7

Browse files
authored
Extend Rcpp.package.skeleton to support URL and BugReports (#1358)
Also flips default package version to a saner '0.0.1'
1 parent d854744 commit 50d8ad7

6 files changed

+64
-44
lines changed

ChangeLog

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2025-02-11 Dirk Eddelbuettel <edd@debian.org>
2+
3+
* R/Rcpp.package.skeleton.R (Rcpp.package.skeleton): Support optional
4+
argument 'github_user' to populate URL and BugReports if given
5+
* man/Rcpp.package.skeleton.Rd: Document new optional argument
6+
7+
* R/Rcpp.package.skeleton.R (Rcpp.package.skeleton): Default version
8+
is now '0.0.1' and not '1.0'
9+
* inst/tinytest/test_rcpp_package_skeleton.R: Adjust test accordingly
10+
* inst/tinytest/test_expose_class.R: Idem
11+
112
2025-02-05 Dirk Eddelbuettel <edd@debian.org>
213

314
* DESCRIPTION (Version, Date): Roll micro version and date

R/Rcpp.package.skeleton.R

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2009 - 2021 Dirk Eddelbuettel and Romain Francois
1+
# Copyright (C) 2009 - 2025 Dirk Eddelbuettel and Romain Francois
22
#
33
# This file is part of Rcpp.
44
#
@@ -24,6 +24,7 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(),
2424
maintainer = if (missing(author)) "Your Name"
2525
else author,
2626
email = "your@email.com",
27+
githubuser = NA_character_,
2728
license = "GPL (>= 2)") {
2829

2930
havePkgKitten <- requireNamespace("pkgKitten", quietly=TRUE)
@@ -90,18 +91,26 @@ Rcpp.package.skeleton <- function(name = "anRpackage", list = character(),
9091
paste(splitname[-length(splitname)], collapse=" "),
9192
splitname[length(splitname)],
9293
email))
93-
#x[, "Author"] <- author
94-
#x[, "Maintainer"] <- sprintf("%s <%s>", maintainer, email)
94+
fields_written <- c("Package", "Type", "Title", "Version", "Date",
95+
"Authors@R", "Description", "License", "Imports", "LinkingTo")
96+
if (!is.na(githubuser)) {
97+
x <- cbind(x, matrix("", 1, 1, dimnames=list("", "URL")))
98+
x[1, "URL"] <- paste0("https://github.com/", githubuser, "/", name)
99+
x <- cbind(x, matrix("", 1, 1, dimnames=list("", "BugReports")))
100+
x[1, "BugReports"] <- paste0("https://github.com/", githubuser, "/", name, "/issues")
101+
102+
fields_written <- c("Package", "Type", "Title", "Version", "Date",
103+
"Authors@R", "Description", "URL", "BugReports",
104+
"License", "Imports", "LinkingTo")
105+
}
106+
95107
x[, "License"] <- license
96108
x[, "Title"] <- "Concise Summary of What the Package Does"
97109
x[, "Description"] <- "More about what it does (maybe more than one line)."
110+
x[, "Version"] <- "0.0.1"
98111
message( " >> added Imports: Rcpp" )
99112
message( " >> added LinkingTo: Rcpp" )
100-
write.dcf(x, file = DESCRIPTION)
101-
write.dcf(x[1, c("Package", "Type", "Title", "Version", "Date",
102-
"Authors@R", "Description", "License", "Imports", "LinkingTo"),
103-
drop = FALSE],
104-
file = DESCRIPTION)
113+
write.dcf(x[1, fields_written, drop = FALSE], file = DESCRIPTION)
105114
}
106115

107116
## add useDynLib and importFrom to NAMESPACE

inst/tinytest/test_attribute_package.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ require(pkg, lib.loc = "templib", character.only = TRUE)
3838

3939
# Test Package
4040
options(verbose=TRUE)
41-
expect_equal(test_no_attributes(list("{A}"), FALSE),list("{A}", FALSE))
41+
expect_equal(test_no_attributes(list("{A}"), FALSE),list("{A}", FALSE))
4242
expect_equal(test_signature(),list("{A}", TRUE))
4343
expect_equal(test_rng_false_signature_invisible_true(),list("{A}", TRUE))
44-
expect_equal(test_rng_false(list("{A}"), FALSE),list("{A}", FALSE))
44+
expect_equal(test_rng_false(list("{A}"), FALSE),list("{A}", FALSE))
4545
expect_equal(test_rng_true(list("{A}"), FALSE),list("{A}", FALSE))
4646
expect_equal(test_rng_true_signature(),list("{A}", TRUE))
4747
expect_equal(test_invisible_true_rng_true(list("{A}"), FALSE),list("{A}", FALSE))
@@ -105,7 +105,7 @@ expect_error({
105105

106106
# test 3, from Enchufa2
107107
# This third example should not compile because of missing end bracket }
108-
# The bracket within the signature is taken as the end bracket, which results in
108+
# The bracket within the signature is taken as the end bracket, which results in
109109
# invalid R code. There are some additional warnings due to the incorrect syntax
110110
expect_warning({
111111
expect_error({

inst/tinytest/test_expose_class.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ setwd(path)
7777
on.exit( setwd(owd), add=TRUE )
7878
R <- shQuote( file.path( R.home( component = "bin" ), "R" ))
7979
system( paste(R, "CMD build", pkg_path) )
80-
gz_name <- paste0(pkg_name, "_1.0.tar.gz")
80+
gz_name <- paste0(pkg_name, "_0.0.1.tar.gz")
8181
expect_true( file.exists(gz_name), info = "can successfully R CMD build the pkg")
8282

8383
## check install + require

inst/tinytest/test_rcpp_package_skeleton.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ owd <- getwd()
8686
setwd(path)
8787
R <- shQuote( file.path( R.home( component = "bin" ), "R" ))
8888
system( paste(R, "CMD build", pkg_path) )
89-
checkTrue( file.exists("foo_1.0.tar.gz"), "can successfully R CMD build the pkg")
89+
checkTrue( file.exists("foo_0.0.1.tar.gz"), "can successfully R CMD build the pkg")
9090
dir.create("templib")
91-
install.packages("foo_1.0.tar.gz", file.path(path, "templib"), repos=NULL, type="source")
91+
install.packages("foo_0.0.1.tar.gz", file.path(path, "templib"), repos=NULL, type="source")
9292
require("foo", file.path(path, "templib"), character.only=TRUE)
9393

9494

@@ -141,7 +141,7 @@ checkTrue(file.exists( file.path(src_path, "rcpp_module.cpp")),
141141

142142
on.exit(unlink(pkg_path, recursive=TRUE))
143143
on.exit( setwd(owd), add=TRUE )
144-
on.exit( unlink( file.path(path, "foo_1.0.tar.gz") ), add=TRUE)
144+
on.exit( unlink( file.path(path, "foo_0.0.1.tar.gz") ), add=TRUE)
145145
on.exit( unlink( file.path(path, "templib"), recursive=TRUE), add=TRUE )
146146
on.exit( unlink(pkg_path, recursive=TRUE), add=TRUE )
147147
on.exit(unlink(pkg_path, recursive=TRUE), add=TRUE)

man/Rcpp.package.skeleton.Rd

+29-29
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
Create a skeleton for a new package depending on Rcpp
55
}
66
\description{
7-
\code{Rcpp.package.skeleton} automates the creation of
8-
a new source package that intends to use features of Rcpp.
9-
7+
\code{Rcpp.package.skeleton} automates the creation of
8+
a new source package that intends to use features of Rcpp.
9+
1010
It is based on the \link[utils]{package.skeleton} function
1111
which it executes first.
1212
}
1313
\usage{
14-
Rcpp.package.skeleton(name = "anRpackage", list = character(),
15-
environment = .GlobalEnv, path = ".", force = FALSE,
14+
Rcpp.package.skeleton(name = "anRpackage", list = character(),
15+
environment = .GlobalEnv, path = ".", force = FALSE,
1616
code_files = character(), cpp_files = character(),
17-
example_code = TRUE, attributes = TRUE, module = FALSE,
18-
author = "Your Name",
19-
maintainer = if(missing( author)) "Your Name" else author,
20-
email = "your@email.com",
17+
example_code = TRUE, attributes = TRUE, module = FALSE,
18+
author = "Your Name",
19+
maintainer = if(missing( author)) "Your Name" else author,
20+
email = "your@email.com", githubuser = NA_character_,
2121
license = "GPL (>= 2)"
2222
)
2323
}
@@ -35,42 +35,43 @@ Rcpp.package.skeleton(name = "anRpackage", list = character(),
3535
\item{author}{Author of the package.}
3636
\item{maintainer}{Maintainer of the package.}
3737
\item{email}{Email of the package maintainer.}
38+
\item{githubuser}{GitHub username for URL and BugReports, if present.}
3839
\item{license}{License of the package.}
3940
}
4041
\details{
41-
In addition to \link[utils]{package.skeleton} :
42-
43-
The \samp{DESCRIPTION} file gains an Imports line requesting that
42+
In addition to \link[utils]{package.skeleton} :
43+
44+
The \samp{DESCRIPTION} file gains an Imports line requesting that
4445
the package depends on Rcpp and a LinkingTo line so that the package
4546
finds Rcpp header files.
46-
47+
4748
The \samp{NAMESPACE} gains a \code{useDynLib} directive as well
4849
as an \code{importFrom(Rcpp, evalCpp} to ensure instantiation of Rcpp.
49-
50-
The \samp{src} directory is created if it does not exists.
51-
50+
51+
The \samp{src} directory is created if it does not exists.
52+
5253
If \code{cpp_files} are provided then they will be copied to the \samp{src}
5354
directory.
54-
55-
If the \code{example_code} argument is set to \code{TRUE},
55+
56+
If the \code{example_code} argument is set to \code{TRUE},
5657
example files \samp{rcpp_hello_world.h} and \samp{rcpp_hello_world.cpp}
57-
are also created in the \samp{src}. An R file \samp{rcpp_hello_world.R} is
58+
are also created in the \samp{src}. An R file \samp{rcpp_hello_world.R} is
5859
expanded in the \samp{R} directory, the \code{rcpp_hello_world} function
5960
defined in this files makes use of the C++ function \samp{rcpp_hello_world}
60-
defined in the C++ file. These files are given as an example and should
61+
defined in the C++ file. These files are given as an example and should
6162
eventually by removed from the generated package.
62-
63+
6364
If the \code{attributes} argument is \code{TRUE}, then rather than generate
6465
the example files as described above, a single \samp{rcpp_hello_world.cpp}
65-
file is created in the \samp{src} directory and it's attributes are
66-
compiled using the \code{\link{compileAttributes}} function. This leads to
66+
file is created in the \samp{src} directory and it's attributes are
67+
compiled using the \code{\link{compileAttributes}} function. This leads to
6768
the files \samp{RcppExports.R} and \samp{RcppExports.cpp} being generated.
68-
They are automatically regenerated from \emph{scratch} each time
69-
\code{\link{compileAttributes}} is called. Therefore, one should
69+
They are automatically regenerated from \emph{scratch} each time
70+
\code{\link{compileAttributes}} is called. Therefore, one should
7071
\strong{not} modify by hand either of the \samp{RcppExports} files.
71-
72-
If the \code{module} argument is \code{TRUE}, a sample Rcpp module will
73-
be generated as well.
72+
73+
If the \code{module} argument is \code{TRUE}, a sample Rcpp module will
74+
be generated as well.
7475
}
7576
\value{
7677
Nothing, used for its side effects
@@ -105,4 +106,3 @@ vignette( "Rcpp-modules" )
105106
}
106107
}
107108
\keyword{ programming }
108-

0 commit comments

Comments
 (0)