Skip to content

Commit dccf906

Browse files
new extension= argument for cpp_register() (#302)
1 parent dae1b6a commit dccf906

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@ Config/Needs/cpp11/cpp_register:
5959
vctrs
6060
Encoding: UTF-8
6161
Roxygen: list(markdown = TRUE)
62-
RoxygenNote: 7.2.1
62+
RoxygenNote: 7.2.2
6363
SystemRequirements: C++11

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
* Silenced an unknown attribute warning specific to the Intel compiler
66
(r-lib/systemfonts#98).
77

8+
* `cpp_register()` gains an argument `extension=` governing the file extension of
9+
the `src/cpp11` file. By default it's `.cpp`, but `.cc` is now supported as well (#292, @MichaelChirico)
10+
811
# cpp11 0.4.3
912

1013
* Modernized the GitHub Actions workflows and updated some internal tests to

R/register.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#' `tibble` and `vctrs` packages must also be installed.
1212
#' @param path The path to the package root directory
1313
#' @param quiet If `TRUE` suppresses output from this function
14+
#' @param extension The file extension to use for the generated src/cpp11 file.
15+
#' `.cpp` by default, but `.cc` is also supported.
1416
#' @return The paths to the generated R and C++ source files (in that order).
1517
#' @export
1618
#' @examples
@@ -34,11 +36,12 @@
3436
#'
3537
#' # cleanup
3638
#' unlink(dir, recursive = TRUE)
37-
cpp_register <- function(path = ".", quiet = !is_interactive()) {
39+
cpp_register <- function(path = ".", quiet = !is_interactive(), extension = c(".cpp", ".cc")) {
3840
stop_unless_installed(get_cpp_register_needs())
41+
extension <- match.arg(extension)
3942

4043
r_path <- file.path(path, "R", "cpp11.R")
41-
cpp_path <- file.path(path, "src", "cpp11.cpp")
44+
cpp_path <- file.path(path, "src", paste0("cpp11", extension))
4245
unlink(c(r_path, cpp_path))
4346

4447
suppressWarnings(

man/cpp_register.Rd

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-register.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,16 @@ extern \"C\" attribute_visible void R_init_testPkg(DllInfo* dll){
718718

719719
expect_error_free(cpp_register(p))
720720
})
721+
722+
it("accepts .cc as an alternative value for extension=", {
723+
pkg <- local_package()
724+
p <- pkg_path(pkg)
725+
dir.create(file.path(p, "src"))
726+
file.copy(test_path("single.cpp"), file.path(p, "src", "single.cc"))
727+
cpp_register(p, extension = ".cc")
728+
729+
expect_match(list.files(file.path(p, "src")), "\\.cc$")
730+
})
721731
})
722732

723733
describe("generate_init_functions", {

0 commit comments

Comments
 (0)