Skip to content

new extension= argument for cpp_register() #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ Config/Needs/cpp11/cpp_register:
vctrs
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.1
RoxygenNote: 7.2.2
SystemRequirements: C++11
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Silenced an unknown attribute warning specific to the Intel compiler
(r-lib/systemfonts#98).

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

# cpp11 0.4.3

* Modernized the GitHub Actions workflows and updated some internal tests to
Expand Down
7 changes: 5 additions & 2 deletions R/register.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#' `tibble` and `vctrs` packages must also be installed.
#' @param path The path to the package root directory
#' @param quiet If `TRUE` suppresses output from this function
#' @param extension The file extension to use for the generated src/cpp11 file.
#' `.cpp` by default, but `.cc` is also supported.
#' @return The paths to the generated R and C++ source files (in that order).
#' @export
#' @examples
Expand All @@ -34,11 +36,12 @@
#'
#' # cleanup
#' unlink(dir, recursive = TRUE)
cpp_register <- function(path = ".", quiet = !is_interactive()) {
cpp_register <- function(path = ".", quiet = !is_interactive(), extension = c(".cpp", ".cc")) {
stop_unless_installed(get_cpp_register_needs())
extension <- match.arg(extension)

r_path <- file.path(path, "R", "cpp11.R")
cpp_path <- file.path(path, "src", "cpp11.cpp")
cpp_path <- file.path(path, "src", paste0("cpp11", extension))
unlink(c(r_path, cpp_path))

suppressWarnings(
Expand Down
9 changes: 8 additions & 1 deletion man/cpp_register.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/testthat/test-register.R
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,16 @@ extern \"C\" attribute_visible void R_init_testPkg(DllInfo* dll){

expect_error_free(cpp_register(p))
})

it("accepts .cc as an alternative value for extension=", {
pkg <- local_package()
p <- pkg_path(pkg)
dir.create(file.path(p, "src"))
file.copy(test_path("single.cpp"), file.path(p, "src", "single.cc"))
cpp_register(p, extension = ".cc")

expect_match(list.files(file.path(p, "src")), "\\.cc$")
})
})

describe("generate_init_functions", {
Expand Down