diff --git a/DESCRIPTION b/DESCRIPTION index d668e342..e533fc9f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -55,4 +55,4 @@ Config/Needs/cpp11/cpp_register: vctrs Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.2.2 diff --git a/R/register.R b/R/register.R index 3ea10d52..5e41fc04 100644 --- a/R/register.R +++ b/R/register.R @@ -67,12 +67,11 @@ cpp_register <- function(path = ".", quiet = !is_interactive(), extension = c(". dir.create(dirname(r_path), recursive = TRUE, showWarnings = FALSE) - brio::write_lines(path = r_path, glue::glue(' + brio::write_lines(path = r_path, glue::glue(" # Generated by cpp11: do not edit by hand {r_functions} - ' - )) + ")) if (!quiet) { cli::cli_alert_success("generated file {.file {basename(r_path)}}") } @@ -85,11 +84,11 @@ cpp_register <- function(path = ".", quiet = !is_interactive(), extension = c(". n_args = viapply(funs$args, nrow) ) - cpp_function_registration <- glue::glue_collapse(cpp_function_registration, sep = "\n") + cpp_function_registration <- glue::glue_collapse(cpp_function_registration, sep = "\n") - extra_includes <- character() + extra_includes <- character() if (pkg_links_to_rcpp(path)) { - extra_includes <- c(extra_includes, "#include ", "#include ", "using namespace Rcpp;") + extra_includes <- c(extra_includes, "#include ", "#include ", "using namespace Rcpp;") } pkg_types <- c( @@ -114,7 +113,7 @@ cpp_register <- function(path = ".", quiet = !is_interactive(), extension = c(". // clang-format off {extra_includes} - #include "cpp11/declarations.hpp" + #include "headers/declarations.hpp" #include {cpp_functions_definitions} @@ -129,7 +128,7 @@ cpp_register <- function(path = ".", quiet = !is_interactive(), extension = c(". R_forceSymbols(dll, TRUE); }} ', - call_entries = glue::glue_collapse(call_entries, "\n") + call_entries = glue::glue_collapse(call_entries, "\n") )) if (!quiet) { @@ -169,7 +168,8 @@ generate_cpp_functions <- function(funs, package = "cpp11") { funs$calls <- mapply(wrap_call, funs$name, funs$return_type, funs$args, SIMPLIFY = TRUE) funs$package <- package - out <- glue::glue_data(funs, + out <- glue::glue_data( + funs, ' // {basename(file)} {return_type} {name}({real_params}); @@ -193,20 +193,22 @@ generate_init_functions <- function(funs) { funs$declaration_params <- vcapply(funs$args, glue_collapse_data, "{type} {name}") funs$call_params <- vcapply(funs$args, `[[`, "name") - declarations <- glue::glue_data(funs, - ' + declarations <- glue::glue_data( + funs, + " {return_type} {name}({declaration_params}); - ' + " ) declarations <- paste0("\n", glue::glue_collapse(declarations, "\n"), "\n") - calls <- glue::glue_data(funs, - ' + calls <- glue::glue_data( + funs, + " {name}({call_params}); - ' + " ) - calls <- paste0("\n", glue::glue_collapse(calls, "\n")); + calls <- paste0("\n", glue::glue_collapse(calls, "\n")) list( declarations = declarations, @@ -221,7 +223,7 @@ generate_r_functions <- function(funs, package = "cpp11", use_package = FALSE) { package_call <- glue::glue(', PACKAGE = "{package}"') package_names <- glue::glue_data(funs, '"_{package}_{name}"') } else { - package_names <- glue::glue_data(funs, '`_{package}_{name}`') + package_names <- glue::glue_data(funs, "`_{package}_{name}`") package_call <- "" } @@ -231,21 +233,21 @@ generate_r_functions <- function(funs, package = "cpp11", use_package = FALSE) { funs$params <- vcapply(funs$list_params, function(x) if (nzchar(x)) paste0(", ", x) else x) is_void <- funs$return_type == "void" funs$calls <- ifelse(is_void, - glue::glue_data(funs, 'invisible(.Call({package_names}{params}{package_call}))'), - glue::glue_data(funs, '.Call({package_names}{params}{package_call})') + glue::glue_data(funs, "invisible(.Call({package_names}{params}{package_call}))"), + glue::glue_data(funs, ".Call({package_names}{params}{package_call})") ) - out <- glue::glue_data(funs, ' + out <- glue::glue_data(funs, " {name} <- function({list_params}) {{ {calls} }} - ') + ") out <- glue::glue_collapse(out, sep = "\n\n") unclass(out) } wrap_call <- function(name, return_type, args) { - call <- glue::glue('{name}({list_params})', list_params = glue_collapse_data(args, "cpp11::as_cpp>({name})")) + call <- glue::glue("{name}({list_params})", list_params = glue_collapse_data(args, "cpp11::as_cpp>({name})")) if (return_type == "void") { unclass(glue::glue(" {call};\n return R_NilValue;", .trim = FALSE)) } else { @@ -256,7 +258,8 @@ wrap_call <- function(name, return_type, args) { get_call_entries <- function(path, names, package) { con <- textConnection("res", local = TRUE, open = "w") - withr::with_collate("C", + withr::with_collate( + "C", tools::package_native_routine_registration_skeleton(path, con, character_only = FALSE, @@ -274,7 +277,7 @@ get_call_entries <- function(path, names, package) { return("") } - redundant <- glue::glue_collapse(glue::glue('extern SEXP _{package}_{names}'), sep = '|') + redundant <- glue::glue_collapse(glue::glue("extern SEXP _{package}_{names}"), sep = "|") if (length(redundant) > 0 && nzchar(redundant)) { redundant <- paste0("^", redundant) @@ -285,7 +288,7 @@ get_call_entries <- function(path, names, package) { call_calls <- startsWith(res, "extern SEXP") - if(any(call_calls)) { + if (any(call_calls)) { return(res[seq(start, end)]) } @@ -306,11 +309,10 @@ get_cpp_register_needs <- function() { } check_valid_attributes <- function(decorations, file = decorations$file) { - bad_decor <- startsWith(decorations$decoration, "cpp11::") & (!decorations$decoration %in% c("cpp11::register", "cpp11::init", "cpp11::linking_to")) - if(any(bad_decor)) { + if (any(bad_decor)) { lines <- decorations$line[bad_decor] names <- decorations$decoration[bad_decor] bad_lines <- glue::glue_collapse(glue::glue("- Invalid attribute `{names}` on @@ -320,6 +322,5 @@ check_valid_attributes <- function(decorations, file = decorations$file) { {bad_lines} ") stop(msg, call. = FALSE) - } } diff --git a/R/source.R b/R/source.R index fc9124d5..5edfd80e 100644 --- a/R/source.R +++ b/R/source.R @@ -24,7 +24,7 @@ #' @examples #' #' cpp_source( -#' code = '#include "cpp11/integers.hpp" +#' code = '#include "headers/integers.hpp" #' #' [[cpp11::register]] #' int num_odd(cpp11::integers x) { @@ -36,15 +36,15 @@ #' } #' return total; #' } -#' ') +#' ' +#' ) #' #' num_odd(as.integer(c(1:10, 15, 23))) #' #' if (interactive() && require("progress")) { -#' -#' cpp_source( -#' code = ' -#' #include +#' cpp_source( +#' code = ' +#' #include #' #include #' #' [[cpp11::linking_to("progress")]] @@ -59,9 +59,10 @@ #' pb.tick(); #' } #' } -#' ') +#' ' +#' ) #' -#' show_progress() +#' show_progress() #' } #' #' @export @@ -96,7 +97,7 @@ cpp_source <- function(file, code = NULL, env = parent.frame(), clean = TRUE, qu # file now points to another location file.copy(file, file.path(new_dir, name)) - #change variable name to reflect this + # change variable name to reflect this new_file_path <- file.path(new_dir, name) new_file_name <- basename(new_file_path) @@ -106,14 +107,14 @@ cpp_source <- function(file, code = NULL, env = parent.frame(), clean = TRUE, qu all_decorations <- decor::cpp_decorations(dir, is_attribute = TRUE) ) - #provide original path for error messages + # provide original path for error messages check_valid_attributes(all_decorations, file = orig_file_path) funs <- get_registered_functions(all_decorations, "cpp11::register", quiet = quiet) cpp_functions_definitions <- generate_cpp_functions(funs, package = package) cpp_path <- file.path(dirname(new_file_path), "cpp11.cpp") - brio::write_lines(c('#include "cpp11/declarations.hpp"', "using namespace ::cpp11;", cpp_functions_definitions), cpp_path) + brio::write_lines(c('#include "headers/declarations.hpp"', "using namespace ::cpp11;", cpp_functions_definitions), cpp_path) linking_to <- union(get_linking_to(all_decorations), "cpp11") @@ -156,7 +157,7 @@ generate_cpp_name <- function(name, loaded_dlls = c("cpp11", names(getLoadedDLLs root <- tools::file_path_sans_ext(basename(name)) count <- 2 new_name <- root - while(new_name %in% loaded_dlls) { + while (new_name %in% loaded_dlls) { new_name <- sprintf("%s_%i", root, count) count <- count + 1 } @@ -184,12 +185,17 @@ generate_makevars <- function(includes, cxx_std) { #' @rdname cpp_source #' @export cpp_function <- function(code, env = parent.frame(), clean = TRUE, quiet = TRUE, cxx_std = Sys.getenv("CXX_STD", "CXX11")) { - cpp_source(code = paste(c('#include "cpp11.hpp"', + cpp_source( + code = paste( + c( + '#include "cpp11.hpp"', "using namespace ::cpp11;", "namespace writable = ::cpp11::writable;", "[[cpp11::register]]", - code), - collapse = "\n"), + code + ), + collapse = "\n" + ), env = env, clean = clean, quiet = quiet, @@ -202,15 +208,20 @@ utils::globalVariables("f") #' @rdname cpp_source #' @export cpp_eval <- function(code, env = parent.frame(), clean = TRUE, quiet = TRUE, cxx_std = Sys.getenv("CXX_STD", "CXX11")) { - cpp_source(code = paste(c('#include "cpp11.hpp"', + cpp_source( + code = paste( + c( + '#include "cpp11.hpp"', "using namespace ::cpp11;", "namespace writable = ::cpp11::writable;", "[[cpp11::register]]", "SEXP f() { return as_sexp(", code, ");", - "}"), - collapse = "\n"), + "}" + ), + collapse = "\n" + ), env = env, clean = clean, quiet = quiet, diff --git a/R/utils.R b/R/utils.R index 0dddfaf9..e4e0e473 100644 --- a/R/utils.R +++ b/R/utils.R @@ -43,18 +43,18 @@ is_windows <- function() { # use for stop_if_not_installed(), because rlang itself could be one of the # input pkgs. is_interactive <- function() { - opt <- getOption("rlang_interactive", NULL) - if (!is.null(opt)) { - return(opt) - } - if (isTRUE(getOption("knitr.in.progress"))) { - return(FALSE) - } - if (isTRUE(getOption("rstudio.notebook.executing"))) { - return(FALSE) - } - if (identical(Sys.getenv("TESTTHAT"), "true")) { - return(FALSE) - } - interactive() + opt <- getOption("rlang_interactive", NULL) + if (!is.null(opt)) { + return(opt) + } + if (isTRUE(getOption("knitr.in.progress"))) { + return(FALSE) + } + if (isTRUE(getOption("rstudio.notebook.executing"))) { + return(FALSE) + } + if (identical(Sys.getenv("TESTTHAT"), "true")) { + return(FALSE) + } + interactive() } diff --git a/R/vendor.R b/R/vendor.R index 5fe10fe2..09148b63 100644 --- a/R/vendor.R +++ b/R/vendor.R @@ -4,18 +4,18 @@ #' project is using. It is often used in the go language community. #' #' This function vendors cpp11 into your package by copying the cpp11 -#' headers into the `inst/include` folder of your package and adding -#' 'cpp11 version: XYZ' to the top of the files, where XYZ is the version of -#' cpp11 currently installed on your machine. +#' headers into the `src/vendor` folder and adding 'cpp11 version: XYZ' to the +#' top of the files, where XYZ is the version of cpp11 currently installed on +#' your machine. #' #' If you choose to vendor the headers you should _remove_ `LinkingTo: -#' cpp11` from your DESCRIPTION. +#' cpp11` from your DESCRIPTION. This is done automatically by this function. #' #' **Note**: vendoring places the responsibility of updating the code on #' **you**. Bugfixes and new features in cpp11 will not be available for your #' code until you run `cpp_vendor()` again. #' -#' @inheritParams cpp_register +#' @param path The path to vendor the code into. #' @return The file path to the vendored code (invisibly). #' @export #' @examples @@ -26,18 +26,18 @@ #' # vendor the cpp11 headers into the directory #' cpp_vendor(dir) #' -#' list.files(file.path(dir, "inst", "include", "cpp11")) +#' list.files(file.path(dir, "src", "vendor")) #' #' # cleanup #' unlink(dir, recursive = TRUE) -cpp_vendor <- function(path = ".") { - new <- file.path(path, "inst", "include", "cpp11") +cpp_vendor <- function(path = "./src/vendor") { + new <- file.path(path, "cpp11") if (dir.exists(new)) { stop("'", new, "' already exists\n * run unlink('", new, "', recursive = TRUE)", call. = FALSE) } - dir.create(new , recursive = TRUE, showWarnings = FALSE) + dir.create(new, recursive = TRUE, showWarnings = FALSE) current <- system.file("include", "cpp11", package = "cpp11") if (!nzchar(current)) { @@ -59,5 +59,67 @@ cpp_vendor <- function(path = ".") { writeLines(c(cpp11_header, readLines(f)), file.path(new, basename(f))) } + # Additional steps to make vendoring work ---- + + # 1. Check if `src/Makevars` exists + makevars_exists <- file.exists("src/Makevars") + + # 2. If makevars exists, it should have a line that reads + # `PKG_CPPFLAGS = -I../inst/include` or similar + + vendor_line <- paste0(" -I", new) + + if (isTRUE(makevars_exists)) { + makevars <- readLines("src/Makevars") + + if (any(grepl("^PKG_CPPFLAGS", makevars))) { + cat("There is a `PKG_CPPFLAGS` line in src/Makevars. It will be modified.\n") + + # which line contains `PKG_CPPFLAGS`? + cppflags_line <- grep("^PKG_CPPFLAGS", makevars) + + # append the vendoring line + if (!grepl(vendor_line, makevars[cppflags_line])) { + makevars[cppflags_line] <- paste0(makevars[cppflags_line], vendor_line) + } + + writeLines(makevars, "src/Makevars") + } else { + # add the line + makevars <- c(makevars, paste0("PKG_CPPFLAGS = ", vendor_line)) + + writeLines(makevars, "src/Makevars") + } + + cat("The existing src/Makevars was modified. Please check it.\n") + } else { + # create the file + writeLines(paste0("PKG_CPPFLAGS = ", vendor_line), "src/Makevars") + + # warn about the change + cat("A new src/Makevars file was created.\n") + } + + # 3. `DESCRIPTION` now should not have `LinkingTo: cpp11` or `LinkingTo: \n\tcpp11` + description <- readLines("DESCRIPTION") + + cpp11_in_desc <- any( + grepl("LinkingTo: cpp11", description), + grepl("LinkingTo: ", description), + grepl(" cpp11", description) + ) + + if (isTRUE(cpp11_in_desc)) { + # remove the lines + description <- description[!grepl("LinkingTo: cpp11", description)] + description <- description[!grepl("LinkingTo: ", description)] + description <- description[!grepl(" cpp11", description)] + + writeLines(description, "DESCRIPTION") + + # warn about the change + cat("`LinkingTo: cpp11` was removed from DESCRIPTION.\n") + } + invisible(new) } diff --git a/cpp11test/bench/grow.R b/cpp11test/bench/grow.R index a7bc7171..4c9b776a 100644 --- a/cpp11test/bench/grow.R +++ b/cpp11test/bench/grow.R @@ -1,9 +1,7 @@ pkgload::load_all("cpp11test") -bench::press(len = 10 ^ (0:7), - { - bench::mark( - .Call(cpp11_grow_, len) - ) - } -) +bench::press(len = 10^(0:7), { + bench::mark( + .Call(cpp11_grow_, len) + ) +}) diff --git a/cpp11test/bench/protect.R b/cpp11test/bench/protect.R index 989a8e1c..f79a3b0d 100644 --- a/cpp11test/bench/protect.R +++ b/cpp11test/bench/protect.R @@ -1,6 +1,7 @@ pkgload::load_all("cpp11test") -bench::press(n = 10000, +bench::press( + n = 10000, bench::mark( protect_one_(1:10, n), protect_one_cpp11_(1:10, n), @@ -9,7 +10,8 @@ bench::press(n = 10000, ) ) -bench::press(n = 10000, +bench::press( + n = 10000, bench::mark( protect_many_(n), protect_many_cpp11_(n), diff --git a/cpp11test/bench/sum.R b/cpp11test/bench/sum.R index 6bf2760d..f4be2e70 100644 --- a/cpp11test/bench/sum.R +++ b/cpp11test/bench/sum.R @@ -8,13 +8,15 @@ cases <- expand.grid( ) # Add special case -cases <- do.call(rbind, +cases <- do.call( + rbind, list( list(len = 3e6, vector = "normal", method = "for2"), list(len = 3e6, vector = "normal", method = "foreach2"), list(len = 3e6, vector = "altrep", method = "foreach2"), - cases) + cases ) +) bench::press( .grid = cases, diff --git a/cpp11test/src/add.cpp b/cpp11test/src/add.cpp index 3a3bb4df..95561c25 100644 --- a/cpp11test/src/add.cpp +++ b/cpp11test/src/add.cpp @@ -1,4 +1,4 @@ -#include "cpp11/doubles.hpp" +#include "headers/doubles.hpp" [[cpp11::register]] SEXP cpp11_add_vec_for_(cpp11::writable::doubles x, double num) { R_xlen_t n = x.size(); diff --git a/cpp11test/src/cpp11.cpp b/cpp11test/src/cpp11.cpp index 6120c333..506b2e6d 100644 --- a/cpp11test/src/cpp11.cpp +++ b/cpp11test/src/cpp11.cpp @@ -1,10 +1,10 @@ // Generated by cpp11: do not edit by hand // clang-format off -#include +#include #include using namespace Rcpp; -#include "cpp11/declarations.hpp" +#include "headers/declarations.hpp" #include // add.cpp diff --git a/cpp11test/src/data_frame.cpp b/cpp11test/src/data_frame.cpp index 08729155..fe4a6fc0 100644 --- a/cpp11test/src/data_frame.cpp +++ b/cpp11test/src/data_frame.cpp @@ -1,6 +1,6 @@ -#include "cpp11/integers.hpp" -#include "cpp11/list.hpp" -#include "cpp11/strings.hpp" +#include "headers/integers.hpp" +#include "headers/list.hpp" +#include "headers/strings.hpp" [[cpp11::register]] SEXP data_frame_() { using namespace cpp11::literals; diff --git a/cpp11test/src/errors.cpp b/cpp11test/src/errors.cpp index 79f061ee..a571902f 100644 --- a/cpp11test/src/errors.cpp +++ b/cpp11test/src/errors.cpp @@ -1,5 +1,5 @@ -#include "cpp11/function.hpp" -#include "cpp11/protect.hpp" +#include "headers/function.hpp" +#include "headers/protect.hpp" using namespace cpp11; [[cpp11::register]] void my_stop_n1fmt(std::string mystring) { cpp11::stop(mystring); } diff --git a/cpp11test/src/errors_fmt.cpp b/cpp11test/src/errors_fmt.cpp index 6c3ef8bc..96bf341d 100644 --- a/cpp11test/src/errors_fmt.cpp +++ b/cpp11test/src/errors_fmt.cpp @@ -1,6 +1,6 @@ #define CPP11_USE_FMT -#include "cpp11/function.hpp" -#include "cpp11/protect.hpp" +#include "headers/function.hpp" +#include "headers/protect.hpp" using namespace cpp11; [[cpp11::register]] void my_stop(std::string mystring, int myarg) { diff --git a/cpp11test/src/grow.cpp b/cpp11test/src/grow.cpp index eb3f620b..ba587029 100644 --- a/cpp11test/src/grow.cpp +++ b/cpp11test/src/grow.cpp @@ -1,4 +1,4 @@ -#include "cpp11/doubles.hpp" +#include "headers/doubles.hpp" [[cpp11::register]] cpp11::writable::doubles grow_(R_xlen_t n) { cpp11::writable::doubles x; diff --git a/cpp11test/src/insert.cpp b/cpp11test/src/insert.cpp index 913d71b8..6a71afe6 100644 --- a/cpp11test/src/insert.cpp +++ b/cpp11test/src/insert.cpp @@ -1,4 +1,4 @@ -#include "cpp11/doubles.hpp" +#include "headers/doubles.hpp" [[cpp11::register]] SEXP cpp11_insert_(SEXP num_sxp) { R_xlen_t num = INTEGER(num_sxp)[0]; diff --git a/cpp11test/src/matrix.cpp b/cpp11test/src/matrix.cpp index 10348945..a484bcff 100644 --- a/cpp11test/src/matrix.cpp +++ b/cpp11test/src/matrix.cpp @@ -1,6 +1,6 @@ -#include "cpp11/matrix.hpp" +#include "headers/matrix.hpp" #include "Rmath.h" -#include "cpp11/doubles.hpp" +#include "headers/doubles.hpp" using namespace cpp11; [[cpp11::register]] SEXP gibbs_cpp(int N, int thin) { diff --git a/cpp11test/src/release.cpp b/cpp11test/src/release.cpp index 7b321e45..6be8d514 100644 --- a/cpp11test/src/release.cpp +++ b/cpp11test/src/release.cpp @@ -1,5 +1,5 @@ #include -#include "cpp11/sexp.hpp" +#include "headers/sexp.hpp" #include "Rcpp.h" diff --git a/cpp11test/src/safe.cpp b/cpp11test/src/safe.cpp index 175f24ec..b12d254d 100644 --- a/cpp11test/src/safe.cpp +++ b/cpp11test/src/safe.cpp @@ -1,6 +1,6 @@ #include -#include "cpp11/doubles.hpp" -#include "cpp11/protect.hpp" +#include "headers/doubles.hpp" +#include "headers/protect.hpp" [[cpp11::register]] SEXP cpp11_safe_(SEXP x_sxp) { SEXP err = R_NilValue; diff --git a/cpp11test/src/sum.cpp b/cpp11test/src/sum.cpp index e685c7d1..25cd691c 100644 --- a/cpp11test/src/sum.cpp +++ b/cpp11test/src/sum.cpp @@ -1,5 +1,5 @@ #include -#include "cpp11/doubles.hpp" +#include "headers/doubles.hpp" [[cpp11::register]] double sum_dbl_for_(cpp11::doubles x) { double sum = 0.; diff --git a/cpp11test/src/sum_int.cpp b/cpp11test/src/sum_int.cpp index 922f6e76..79bd22af 100644 --- a/cpp11test/src/sum_int.cpp +++ b/cpp11test/src/sum_int.cpp @@ -1,5 +1,5 @@ #include -#include "cpp11/integers.hpp" +#include "headers/integers.hpp" [[cpp11::register]] double sum_int_for_(cpp11::integers x) { double sum = 0.; diff --git a/cpp11test/src/test-as.cpp b/cpp11test/src/test-as.cpp index ddbb9974..ca087f0b 100644 --- a/cpp11test/src/test-as.cpp +++ b/cpp11test/src/test-as.cpp @@ -2,7 +2,7 @@ #include #include -#include "cpp11/declarations.hpp" +#include "headers/declarations.hpp" #include diff --git a/cpp11test/src/test-data_frame.cpp b/cpp11test/src/test-data_frame.cpp index e692712b..20f67bd9 100644 --- a/cpp11test/src/test-data_frame.cpp +++ b/cpp11test/src/test-data_frame.cpp @@ -1,7 +1,7 @@ -#include "cpp11/data_frame.hpp" -#include "cpp11/function.hpp" -#include "cpp11/integers.hpp" -#include "cpp11/strings.hpp" +#include "headers/data_frame.hpp" +#include "headers/function.hpp" +#include "headers/integers.hpp" +#include "headers/strings.hpp" #include diff --git a/cpp11test/src/test-doubles.cpp b/cpp11test/src/test-doubles.cpp index a7423e1e..31216cc2 100644 --- a/cpp11test/src/test-doubles.cpp +++ b/cpp11test/src/test-doubles.cpp @@ -1,9 +1,9 @@ #include -#include "cpp11/doubles.hpp" -#include "cpp11/function.hpp" -#include "cpp11/integers.hpp" -#include "cpp11/sexp.hpp" -#include "cpp11/strings.hpp" +#include "headers/doubles.hpp" +#include "headers/function.hpp" +#include "headers/integers.hpp" +#include "headers/sexp.hpp" +#include "headers/strings.hpp" #include diff --git a/cpp11test/src/test-environment.cpp b/cpp11test/src/test-environment.cpp index 370b6018..55b2b57a 100644 --- a/cpp11test/src/test-environment.cpp +++ b/cpp11test/src/test-environment.cpp @@ -1,7 +1,7 @@ -#include "cpp11/as.hpp" -#include "cpp11/environment.hpp" -#include "cpp11/function.hpp" -#include "cpp11/strings.hpp" +#include "headers/as.hpp" +#include "headers/environment.hpp" +#include "headers/function.hpp" +#include "headers/strings.hpp" #include diff --git a/cpp11test/src/test-external_pointer.cpp b/cpp11test/src/test-external_pointer.cpp index 897fd4f2..325760c5 100644 --- a/cpp11test/src/test-external_pointer.cpp +++ b/cpp11test/src/test-external_pointer.cpp @@ -1,5 +1,5 @@ #include -#include "cpp11/external_pointer.hpp" +#include "headers/external_pointer.hpp" #include diff --git a/cpp11test/src/test-function.cpp b/cpp11test/src/test-function.cpp index 678a5ee2..c19e4139 100644 --- a/cpp11test/src/test-function.cpp +++ b/cpp11test/src/test-function.cpp @@ -1,4 +1,4 @@ -#include "cpp11/function.hpp" +#include "headers/function.hpp" #include diff --git a/cpp11test/src/test-integers.cpp b/cpp11test/src/test-integers.cpp index 6f876c57..ef4d3896 100644 --- a/cpp11test/src/test-integers.cpp +++ b/cpp11test/src/test-integers.cpp @@ -1,8 +1,8 @@ #include "Rversion.h" -#include "cpp11/doubles.hpp" -#include "cpp11/function.hpp" -#include "cpp11/integers.hpp" -#include "cpp11/strings.hpp" +#include "headers/doubles.hpp" +#include "headers/function.hpp" +#include "headers/integers.hpp" +#include "headers/strings.hpp" #include diff --git a/cpp11test/src/test-list.cpp b/cpp11test/src/test-list.cpp index 0abf6002..51738f62 100644 --- a/cpp11test/src/test-list.cpp +++ b/cpp11test/src/test-list.cpp @@ -1,9 +1,9 @@ -#include "cpp11/doubles.hpp" -#include "cpp11/integers.hpp" -#include "cpp11/list.hpp" -#include "cpp11/logicals.hpp" -#include "cpp11/raws.hpp" -#include "cpp11/strings.hpp" +#include "headers/doubles.hpp" +#include "headers/integers.hpp" +#include "headers/list.hpp" +#include "headers/logicals.hpp" +#include "headers/raws.hpp" +#include "headers/strings.hpp" #include diff --git a/cpp11test/src/test-list_of.cpp b/cpp11test/src/test-list_of.cpp index 08d62dcf..930addfb 100644 --- a/cpp11test/src/test-list_of.cpp +++ b/cpp11test/src/test-list_of.cpp @@ -1,7 +1,7 @@ -#include "cpp11/doubles.hpp" -#include "cpp11/list.hpp" -#include "cpp11/list_of.hpp" -#include "cpp11/strings.hpp" +#include "headers/doubles.hpp" +#include "headers/list.hpp" +#include "headers/list_of.hpp" +#include "headers/strings.hpp" #include diff --git a/cpp11test/src/test-logicals.cpp b/cpp11test/src/test-logicals.cpp index 6c9b136a..170c412e 100644 --- a/cpp11test/src/test-logicals.cpp +++ b/cpp11test/src/test-logicals.cpp @@ -1,4 +1,4 @@ -#include "cpp11/logicals.hpp" +#include "headers/logicals.hpp" #include diff --git a/cpp11test/src/test-matrix.cpp b/cpp11test/src/test-matrix.cpp index 693d6ec7..4b98c9fb 100644 --- a/cpp11test/src/test-matrix.cpp +++ b/cpp11test/src/test-matrix.cpp @@ -1,7 +1,7 @@ -#include "cpp11/doubles.hpp" -#include "cpp11/function.hpp" -#include "cpp11/integers.hpp" -#include "cpp11/matrix.hpp" +#include "headers/doubles.hpp" +#include "headers/function.hpp" +#include "headers/integers.hpp" +#include "headers/matrix.hpp" #include diff --git a/cpp11test/src/test-nas.cpp b/cpp11test/src/test-nas.cpp index a0ca5848..dcaf4024 100644 --- a/cpp11test/src/test-nas.cpp +++ b/cpp11test/src/test-nas.cpp @@ -1,7 +1,7 @@ -#include "cpp11/doubles.hpp" -#include "cpp11/integers.hpp" -#include "cpp11/r_bool.hpp" -#include "cpp11/r_string.hpp" +#include "headers/doubles.hpp" +#include "headers/integers.hpp" +#include "headers/r_bool.hpp" +#include "headers/r_string.hpp" #include diff --git a/cpp11test/src/test-protect-nested.cpp b/cpp11test/src/test-protect-nested.cpp index 2679a5f7..384a62d9 100644 --- a/cpp11test/src/test-protect-nested.cpp +++ b/cpp11test/src/test-protect-nested.cpp @@ -1,5 +1,5 @@ -#include "cpp11/function.hpp" -#include "cpp11/protect.hpp" +#include "headers/function.hpp" +#include "headers/protect.hpp" #include "testthat.h" #ifdef HAS_UNWIND_PROTECT diff --git a/cpp11test/src/test-protect.cpp b/cpp11test/src/test-protect.cpp index 2bd2dadf..323029c6 100644 --- a/cpp11test/src/test-protect.cpp +++ b/cpp11test/src/test-protect.cpp @@ -12,7 +12,7 @@ // clang-format on #define CPP11_USE_FMT -#include "cpp11/protect.hpp" +#include "headers/protect.hpp" #include "testthat.h" #ifdef HAS_UNWIND_PROTECT diff --git a/cpp11test/src/test-raws.cpp b/cpp11test/src/test-raws.cpp index ecae6db6..c3f0fd25 100644 --- a/cpp11test/src/test-raws.cpp +++ b/cpp11test/src/test-raws.cpp @@ -1,4 +1,4 @@ -#include "cpp11/raws.hpp" +#include "headers/raws.hpp" #include diff --git a/cpp11test/src/test-sexp.cpp b/cpp11test/src/test-sexp.cpp index d9e7800e..9acee94a 100644 --- a/cpp11test/src/test-sexp.cpp +++ b/cpp11test/src/test-sexp.cpp @@ -1,4 +1,4 @@ -#include "cpp11/list.hpp" +#include "headers/list.hpp" #include diff --git a/cpp11test/src/test-string.cpp b/cpp11test/src/test-string.cpp index 98661a53..0953744f 100644 --- a/cpp11test/src/test-string.cpp +++ b/cpp11test/src/test-string.cpp @@ -1,4 +1,4 @@ -#include "cpp11/strings.hpp" +#include "headers/strings.hpp" #include diff --git a/cpp11test/src/test-strings.cpp b/cpp11test/src/test-strings.cpp index 3a11e935..7584be1b 100644 --- a/cpp11test/src/test-strings.cpp +++ b/cpp11test/src/test-strings.cpp @@ -1,6 +1,6 @@ #include -#include "cpp11/sexp.hpp" -#include "cpp11/strings.hpp" +#include "headers/sexp.hpp" +#include "headers/strings.hpp" #include diff --git a/cpp11test/tests/testthat/test-doubles.R b/cpp11test/tests/testthat/test-doubles.R index a7016bd0..fa5197f7 100644 --- a/cpp11test/tests/testthat/test-doubles.R +++ b/cpp11test/tests/testthat/test-doubles.R @@ -1,5 +1,4 @@ test_that("doubles iterators work with normal vectors", { - len <- 1e5 set.seed(42) x <- rnorm(len) @@ -12,7 +11,6 @@ test_that("doubles iterators work with normal vectors", { }) test_that("doubles iterators work with altrep vectors", { - len <- 1e5 seq_double <- function(x) as.double(seq_len(x)) diff --git a/cpp11test/tests/testthat/test-matrix.R b/cpp11test/tests/testthat/test-matrix.R index a43f59b0..34df89ca 100644 --- a/cpp11test/tests/testthat/test-matrix.R +++ b/cpp11test/tests/testthat/test-matrix.R @@ -7,7 +7,7 @@ test_that("row_sums gives same result as rowSums", { expect_equal(row_sums(x), rowSums(x)) y <- cbind(x1 = 3, x2 = c(4:1, 2:5)) - y[3, ] <- NA; + y[3, ] <- NA expect_equal(row_sums(y), rowSums(y)) }) @@ -20,6 +20,6 @@ test_that("col_sums gives same result as colSums", { expect_equal(col_sums(x), colSums(x)) y <- cbind(3, c(4:1, 2:5)) - y[3, ] <- NA; + y[3, ] <- NA expect_equal(col_sums(y), colSums(y)) }) diff --git a/cpp11test/tests/testthat/test_formatted_errors.R b/cpp11test/tests/testthat/test_formatted_errors.R index f4cfa8e5..f5ec6cc3 100644 --- a/cpp11test/tests/testthat/test_formatted_errors.R +++ b/cpp11test/tests/testthat/test_formatted_errors.R @@ -5,7 +5,8 @@ test_that("cpp11::stop formatting works", { test2 <- c(3, 5, 7) expect_error(my_stop("You've tested this {} times", test2[1]), "You've tested this 3 times", - fixed = TRUE) + fixed = TRUE + ) }) test_that("cpp11::warning formatting works", { test1 <- "warning" diff --git a/inst/include/cpp11.hpp b/inst/include/cpp11.hpp index 71e1cf1d..fa81c052 100644 --- a/inst/include/cpp11.hpp +++ b/inst/include/cpp11.hpp @@ -1,24 +1,24 @@ #pragma once -#include "cpp11/R.hpp" -#include "cpp11/altrep.hpp" -#include "cpp11/as.hpp" -#include "cpp11/attribute_proxy.hpp" -#include "cpp11/data_frame.hpp" -#include "cpp11/doubles.hpp" -#include "cpp11/environment.hpp" -#include "cpp11/external_pointer.hpp" -#include "cpp11/function.hpp" -#include "cpp11/integers.hpp" -#include "cpp11/list.hpp" -#include "cpp11/list_of.hpp" -#include "cpp11/logicals.hpp" -#include "cpp11/matrix.hpp" -#include "cpp11/named_arg.hpp" -#include "cpp11/protect.hpp" -#include "cpp11/r_bool.hpp" -#include "cpp11/r_string.hpp" -#include "cpp11/r_vector.hpp" -#include "cpp11/raws.hpp" -#include "cpp11/sexp.hpp" -#include "cpp11/strings.hpp" +#include "headers/R.hpp" +#include "headers/altrep.hpp" +#include "headers/as.hpp" +#include "headers/attribute_proxy.hpp" +#include "headers/data_frame.hpp" +#include "headers/doubles.hpp" +#include "headers/environment.hpp" +#include "headers/external_pointer.hpp" +#include "headers/function.hpp" +#include "headers/integers.hpp" +#include "headers/list.hpp" +#include "headers/list_of.hpp" +#include "headers/logicals.hpp" +#include "headers/matrix.hpp" +#include "headers/named_arg.hpp" +#include "headers/protect.hpp" +#include "headers/r_bool.hpp" +#include "headers/r_string.hpp" +#include "headers/r_vector.hpp" +#include "headers/raws.hpp" +#include "headers/sexp.hpp" +#include "headers/strings.hpp" diff --git a/inst/include/cpp11/R.hpp b/inst/include/headers/R.hpp similarity index 97% rename from inst/include/cpp11/R.hpp rename to inst/include/headers/R.hpp index 8d6751f1..91f2d40f 100644 --- a/inst/include/cpp11/R.hpp +++ b/inst/include/headers/R.hpp @@ -25,7 +25,7 @@ // clang-format on #include -#include "cpp11/altrep.hpp" +#include "headers/altrep.hpp" namespace cpp11 { namespace literals { diff --git a/inst/include/cpp11/altrep.hpp b/inst/include/headers/altrep.hpp similarity index 100% rename from inst/include/cpp11/altrep.hpp rename to inst/include/headers/altrep.hpp diff --git a/inst/include/cpp11/as.hpp b/inst/include/headers/as.hpp similarity index 98% rename from inst/include/cpp11/as.hpp rename to inst/include/headers/as.hpp index 682f12b5..255ed8cf 100644 --- a/inst/include/cpp11/as.hpp +++ b/inst/include/headers/as.hpp @@ -7,8 +7,8 @@ #include // for string, basic_string #include // for decay, enable_if, is_same, is_convertible -#include "cpp11/R.hpp" // for SEXP, SEXPREC, Rf_xlength, R_xlen_t -#include "cpp11/protect.hpp" // for stop, protect, safe, protect::function +#include "headers/R.hpp" // for SEXP, SEXPREC, Rf_xlength, R_xlen_t +#include "headers/protect.hpp" // for stop, protect, safe, protect::function namespace cpp11 { diff --git a/inst/include/cpp11/attribute_proxy.hpp b/inst/include/headers/attribute_proxy.hpp similarity index 84% rename from inst/include/cpp11/attribute_proxy.hpp rename to inst/include/headers/attribute_proxy.hpp index 64e7436b..c0adf44d 100644 --- a/inst/include/cpp11/attribute_proxy.hpp +++ b/inst/include/headers/attribute_proxy.hpp @@ -3,9 +3,9 @@ #include // for initializer_list #include // for string, basic_string -#include "cpp11/R.hpp" // for SEXP, SEXPREC, Rf_install, PROTECT, Rf_... -#include "cpp11/as.hpp" // for as_sexp -#include "cpp11/protect.hpp" // for protect, safe, protect::function +#include "headers/R.hpp" // for SEXP, SEXPREC, Rf_install, PROTECT, Rf_... +#include "headers/as.hpp" // for as_sexp +#include "headers/protect.hpp" // for protect, safe, protect::function namespace cpp11 { diff --git a/inst/include/cpp11/data_frame.hpp b/inst/include/headers/data_frame.hpp similarity index 90% rename from inst/include/cpp11/data_frame.hpp rename to inst/include/headers/data_frame.hpp index f1caad51..4a652062 100644 --- a/inst/include/cpp11/data_frame.hpp +++ b/inst/include/headers/data_frame.hpp @@ -7,10 +7,10 @@ #include // for move #include "R_ext/Arith.h" // for NA_INTEGER -#include "cpp11/R.hpp" // for Rf_xlength, SEXP, SEXPREC, INTEGER -#include "cpp11/attribute_proxy.hpp" // for attribute_proxy -#include "cpp11/list.hpp" // for list, r_vector<>::r_vector, r_v... -#include "cpp11/r_vector.hpp" // for r_vector +#include "headers/R.hpp" // for Rf_xlength, SEXP, SEXPREC, INTEGER +#include "headers/attribute_proxy.hpp" // for attribute_proxy +#include "headers/list.hpp" // for list, r_vector<>::r_vector, r_v... +#include "headers/r_vector.hpp" // for r_vector namespace cpp11 { diff --git a/inst/include/cpp11/declarations.hpp b/inst/include/headers/declarations.hpp similarity index 100% rename from inst/include/cpp11/declarations.hpp rename to inst/include/headers/declarations.hpp diff --git a/inst/include/cpp11/doubles.hpp b/inst/include/headers/doubles.hpp similarity index 91% rename from inst/include/cpp11/doubles.hpp rename to inst/include/headers/doubles.hpp index 9782346d..ff373bb2 100644 --- a/inst/include/cpp11/doubles.hpp +++ b/inst/include/headers/doubles.hpp @@ -5,12 +5,12 @@ #include // for initializer_list #include "R_ext/Arith.h" // for ISNA -#include "cpp11/R.hpp" // for SEXP, SEXPREC, Rf_allocVector, REAL -#include "cpp11/as.hpp" // for as_sexp -#include "cpp11/named_arg.hpp" // for named_arg -#include "cpp11/protect.hpp" // for SEXP, SEXPREC, REAL_ELT, R_Preserve... -#include "cpp11/r_vector.hpp" // for vector, vector<>::proxy, vector<>::... -#include "cpp11/sexp.hpp" // for sexp +#include "headers/R.hpp" // for SEXP, SEXPREC, Rf_allocVector, REAL +#include "headers/as.hpp" // for as_sexp +#include "headers/named_arg.hpp" // for named_arg +#include "headers/protect.hpp" // for SEXP, SEXPREC, REAL_ELT, R_Preserve... +#include "headers/r_vector.hpp" // for vector, vector<>::proxy, vector<>::... +#include "headers/sexp.hpp" // for sexp // Specializations for doubles diff --git a/inst/include/cpp11/environment.hpp b/inst/include/headers/environment.hpp similarity index 86% rename from inst/include/cpp11/environment.hpp rename to inst/include/headers/environment.hpp index 64fbc553..0b1df9de 100644 --- a/inst/include/cpp11/environment.hpp +++ b/inst/include/headers/environment.hpp @@ -3,17 +3,17 @@ #include // for string, basic_string #include "Rversion.h" // for R_VERSION, R_Version -#include "cpp11/R.hpp" // for SEXP, SEXPREC, Rf_install, Rf_findVarIn... -#include "cpp11/as.hpp" // for as_sexp -#include "cpp11/protect.hpp" // for protect, protect::function, safe, unwin... -#include "cpp11/sexp.hpp" // for sexp +#include "headers/R.hpp" // for SEXP, SEXPREC, Rf_install, Rf_findVarIn... +#include "headers/as.hpp" // for as_sexp +#include "headers/protect.hpp" // for protect, protect::function, safe, unwin... +#include "headers/sexp.hpp" // for sexp #if R_VERSION >= R_Version(4, 0, 0) #define HAS_REMOVE_VAR_FROM_FRAME #endif #ifndef HAS_REMOVE_VAR_FROM_FRAME -#include "cpp11/function.hpp" +#include "headers/function.hpp" #endif namespace cpp11 { diff --git a/inst/include/cpp11/external_pointer.hpp b/inst/include/headers/external_pointer.hpp similarity index 92% rename from inst/include/cpp11/external_pointer.hpp rename to inst/include/headers/external_pointer.hpp index 6956b061..5a83fa42 100644 --- a/inst/include/cpp11/external_pointer.hpp +++ b/inst/include/headers/external_pointer.hpp @@ -4,11 +4,11 @@ #include // for bad_weak_ptr #include // for add_lvalue_reference -#include "cpp11/R.hpp" // for SEXP, SEXPREC, TYPEOF, R_NilValue, R_C... -#include "cpp11/protect.hpp" // for protect, safe, protect::function -#include "cpp11/r_bool.hpp" // for r_bool -#include "cpp11/r_vector.hpp" // for type_error -#include "cpp11/sexp.hpp" // for sexp +#include "headers/R.hpp" // for SEXP, SEXPREC, TYPEOF, R_NilValue, R_C... +#include "headers/protect.hpp" // for protect, safe, protect::function +#include "headers/r_bool.hpp" // for r_bool +#include "headers/r_vector.hpp" // for type_error +#include "headers/sexp.hpp" // for sexp namespace cpp11 { diff --git a/inst/include/cpp11/function.hpp b/inst/include/headers/function.hpp similarity index 90% rename from inst/include/cpp11/function.hpp rename to inst/include/headers/function.hpp index c1679d97..68549dbf 100644 --- a/inst/include/cpp11/function.hpp +++ b/inst/include/headers/function.hpp @@ -6,11 +6,11 @@ #include // for string, basic_string #include // for forward -#include "cpp11/R.hpp" // for SEXP, SEXPREC, CDR, Rf_install, SETCAR -#include "cpp11/as.hpp" // for as_sexp -#include "cpp11/named_arg.hpp" // for named_arg -#include "cpp11/protect.hpp" // for protect, protect::function, safe -#include "cpp11/sexp.hpp" // for sexp +#include "headers/R.hpp" // for SEXP, SEXPREC, CDR, Rf_install, SETCAR +#include "headers/as.hpp" // for as_sexp +#include "headers/named_arg.hpp" // for named_arg +#include "headers/protect.hpp" // for protect, protect::function, safe +#include "headers/sexp.hpp" // for sexp namespace cpp11 { diff --git a/inst/include/cpp11/integers.hpp b/inst/include/headers/integers.hpp similarity index 90% rename from inst/include/cpp11/integers.hpp rename to inst/include/headers/integers.hpp index 1159e2f3..a268841e 100644 --- a/inst/include/cpp11/integers.hpp +++ b/inst/include/headers/integers.hpp @@ -5,13 +5,13 @@ #include // for initializer_list #include "R_ext/Arith.h" // for NA_INTEGER -#include "cpp11/R.hpp" // for SEXP, SEXPREC, Rf_allocVector -#include "cpp11/as.hpp" // for as_sexp -#include "cpp11/attribute_proxy.hpp" // for attribute_proxy -#include "cpp11/named_arg.hpp" // for named_arg -#include "cpp11/protect.hpp" // for preserved -#include "cpp11/r_vector.hpp" // for r_vector, r_vector<>::proxy -#include "cpp11/sexp.hpp" // for sexp +#include "headers/R.hpp" // for SEXP, SEXPREC, Rf_allocVector +#include "headers/as.hpp" // for as_sexp +#include "headers/attribute_proxy.hpp" // for attribute_proxy +#include "headers/named_arg.hpp" // for named_arg +#include "headers/protect.hpp" // for preserved +#include "headers/r_vector.hpp" // for r_vector, r_vector<>::proxy +#include "headers/sexp.hpp" // for sexp // Specializations for integers diff --git a/inst/include/cpp11/list.hpp b/inst/include/headers/list.hpp similarity index 88% rename from inst/include/cpp11/list.hpp rename to inst/include/headers/list.hpp index 64dd987b..72af2fc0 100644 --- a/inst/include/cpp11/list.hpp +++ b/inst/include/headers/list.hpp @@ -2,13 +2,13 @@ #include // for initializer_list -#include "cpp11/R.hpp" // for SEXP, SEXPREC, SET_VECTOR_ELT -#include "cpp11/attribute_proxy.hpp" // for attribute_proxy -#include "cpp11/named_arg.hpp" // for named_arg -#include "cpp11/protect.hpp" // for preserved -#include "cpp11/r_string.hpp" // for r_string -#include "cpp11/r_vector.hpp" // for r_vector, r_vector<>::proxy -#include "cpp11/sexp.hpp" // for sexp +#include "headers/R.hpp" // for SEXP, SEXPREC, SET_VECTOR_ELT +#include "headers/attribute_proxy.hpp" // for attribute_proxy +#include "headers/named_arg.hpp" // for named_arg +#include "headers/protect.hpp" // for preserved +#include "headers/r_string.hpp" // for r_string +#include "headers/r_vector.hpp" // for r_vector, r_vector<>::proxy +#include "headers/sexp.hpp" // for sexp // Specializations for list diff --git a/inst/include/cpp11/list_of.hpp b/inst/include/headers/list_of.hpp similarity index 93% rename from inst/include/cpp11/list_of.hpp rename to inst/include/headers/list_of.hpp index bd5ddd86..8dcdeb1d 100644 --- a/inst/include/cpp11/list_of.hpp +++ b/inst/include/headers/list_of.hpp @@ -2,8 +2,8 @@ #include // for string, basic_string -#include "cpp11/R.hpp" // for R_xlen_t, SEXP, SEXPREC, LONG_VECTOR_SUPPORT -#include "cpp11/list.hpp" // for list +#include "headers/R.hpp" // for R_xlen_t, SEXP, SEXPREC, LONG_VECTOR_SUPPORT +#include "headers/list.hpp" // for list namespace cpp11 { diff --git a/inst/include/cpp11/logicals.hpp b/inst/include/headers/logicals.hpp similarity index 89% rename from inst/include/cpp11/logicals.hpp rename to inst/include/headers/logicals.hpp index 6a4e2cfa..d0e0e78e 100644 --- a/inst/include/cpp11/logicals.hpp +++ b/inst/include/headers/logicals.hpp @@ -4,13 +4,13 @@ #include // for array #include // for initializer_list -#include "cpp11/R.hpp" // for SEXP, SEXPREC, Rf_all... -#include "cpp11/attribute_proxy.hpp" // for attribute_proxy -#include "cpp11/named_arg.hpp" // for named_arg -#include "cpp11/protect.hpp" // for preserved -#include "cpp11/r_bool.hpp" // for r_bool -#include "cpp11/r_vector.hpp" // for r_vector, r_vector<>::proxy -#include "cpp11/sexp.hpp" // for sexp +#include "headers/R.hpp" // for SEXP, SEXPREC, Rf_all... +#include "headers/attribute_proxy.hpp" // for attribute_proxy +#include "headers/named_arg.hpp" // for named_arg +#include "headers/protect.hpp" // for preserved +#include "headers/r_bool.hpp" // for r_bool +#include "headers/r_vector.hpp" // for r_vector, r_vector<>::proxy +#include "headers/sexp.hpp" // for sexp // Specializations for logicals diff --git a/inst/include/cpp11/matrix.hpp b/inst/include/headers/matrix.hpp similarity index 96% rename from inst/include/cpp11/matrix.hpp rename to inst/include/headers/matrix.hpp index 9a8454fe..34942ffc 100644 --- a/inst/include/cpp11/matrix.hpp +++ b/inst/include/headers/matrix.hpp @@ -3,11 +3,11 @@ #include #include // for string -#include "cpp11/R.hpp" // for SEXP, SEXPREC, R_xlen_t, INT... -#include "cpp11/r_bool.hpp" // for r_bool -#include "cpp11/r_string.hpp" // for r_string -#include "cpp11/r_vector.hpp" // for r_vector -#include "cpp11/sexp.hpp" // for sexp +#include "headers/R.hpp" // for SEXP, SEXPREC, R_xlen_t, INT... +#include "headers/r_bool.hpp" // for r_bool +#include "headers/r_string.hpp" // for r_string +#include "headers/r_vector.hpp" // for r_vector +#include "headers/sexp.hpp" // for sexp namespace cpp11 { diff --git a/inst/include/cpp11/named_arg.hpp b/inst/include/headers/named_arg.hpp similarity index 86% rename from inst/include/cpp11/named_arg.hpp rename to inst/include/headers/named_arg.hpp index 1768821a..0fda14ae 100644 --- a/inst/include/cpp11/named_arg.hpp +++ b/inst/include/headers/named_arg.hpp @@ -4,9 +4,9 @@ #include // for initializer_list -#include "cpp11/R.hpp" // for SEXP, SEXPREC, literals -#include "cpp11/as.hpp" // for as_sexp -#include "cpp11/sexp.hpp" // for sexp +#include "headers/R.hpp" // for SEXP, SEXPREC, literals +#include "headers/as.hpp" // for as_sexp +#include "headers/sexp.hpp" // for sexp namespace cpp11 { class named_arg { diff --git a/inst/include/cpp11/protect.hpp b/inst/include/headers/protect.hpp similarity index 98% rename from inst/include/cpp11/protect.hpp rename to inst/include/headers/protect.hpp index 86d7fccc..f1bd0483 100644 --- a/inst/include/cpp11/protect.hpp +++ b/inst/include/headers/protect.hpp @@ -6,8 +6,8 @@ #include // for string, basic_string #include // for tuple, make_tuple -// NB: cpp11/R.hpp must precede R_ext/Error.h to ensure R_NO_REMAP is defined -#include "cpp11/R.hpp" // for SEXP, SEXPREC, CDR, R_NilValue, CAR, R_Pres... +// NB: headers/R.hpp must precede R_ext/Error.h to ensure R_NO_REMAP is defined +#include "headers/R.hpp" // for SEXP, SEXPREC, CDR, R_NilValue, CAR, R_Pres... #include "R_ext/Boolean.h" // for Rboolean #include "R_ext/Error.h" // for Rf_error, Rf_warning diff --git a/inst/include/cpp11/r_bool.hpp b/inst/include/headers/r_bool.hpp similarity index 88% rename from inst/include/cpp11/r_bool.hpp rename to inst/include/headers/r_bool.hpp index a3bb18eb..af1448f8 100644 --- a/inst/include/cpp11/r_bool.hpp +++ b/inst/include/headers/r_bool.hpp @@ -5,11 +5,11 @@ #include // for is_convertible, enable_if #include "R_ext/Boolean.h" // for Rboolean -#include "cpp11/R.hpp" // for SEXP, SEXPREC, ... -#include "cpp11/as.hpp" // for as_sexp -#include "cpp11/protect.hpp" // for unwind_protect, preserved -#include "cpp11/r_vector.hpp" -#include "cpp11/sexp.hpp" // for sexp +#include "headers/R.hpp" // for SEXP, SEXPREC, ... +#include "headers/as.hpp" // for as_sexp +#include "headers/protect.hpp" // for unwind_protect, preserved +#include "headers/r_vector.hpp" +#include "headers/sexp.hpp" // for sexp namespace cpp11 { diff --git a/inst/include/cpp11/r_string.hpp b/inst/include/headers/r_string.hpp similarity index 90% rename from inst/include/cpp11/r_string.hpp rename to inst/include/headers/r_string.hpp index 692b66ea..cf75a087 100644 --- a/inst/include/cpp11/r_string.hpp +++ b/inst/include/headers/r_string.hpp @@ -4,10 +4,10 @@ #include // for is_convertible, enable_if #include "R_ext/Memory.h" // for vmaxget, vmaxset -#include "cpp11/R.hpp" // for SEXP, SEXPREC, Rf_mkCharCE, Rf_translat... -#include "cpp11/as.hpp" // for as_sexp -#include "cpp11/protect.hpp" // for unwind_protect, protect, protect::function -#include "cpp11/sexp.hpp" // for sexp +#include "headers/R.hpp" // for SEXP, SEXPREC, Rf_mkCharCE, Rf_translat... +#include "headers/as.hpp" // for as_sexp +#include "headers/protect.hpp" // for unwind_protect, protect, protect::function +#include "headers/sexp.hpp" // for sexp namespace cpp11 { diff --git a/inst/include/cpp11/r_vector.hpp b/inst/include/headers/r_vector.hpp similarity index 98% rename from inst/include/cpp11/r_vector.hpp rename to inst/include/headers/r_vector.hpp index 4831c2f5..ec97c9cf 100644 --- a/inst/include/cpp11/r_vector.hpp +++ b/inst/include/headers/r_vector.hpp @@ -13,11 +13,11 @@ #include // for decay, is_same, enable_if, is_c... #include // for declval -#include "cpp11/R.hpp" // for R_xlen_t, SEXP, SEXPREC, Rf_xle... -#include "cpp11/attribute_proxy.hpp" // for attribute_proxy -#include "cpp11/protect.hpp" // for preserved -#include "cpp11/r_string.hpp" // for r_string -#include "cpp11/sexp.hpp" // for sexp +#include "headers/R.hpp" // for R_xlen_t, SEXP, SEXPREC, Rf_xle... +#include "headers/attribute_proxy.hpp" // for attribute_proxy +#include "headers/protect.hpp" // for preserved +#include "headers/r_string.hpp" // for r_string +#include "headers/sexp.hpp" // for sexp namespace cpp11 { diff --git a/inst/include/cpp11/raws.hpp b/inst/include/headers/raws.hpp similarity index 90% rename from inst/include/cpp11/raws.hpp rename to inst/include/headers/raws.hpp index a5cb392f..c441126e 100644 --- a/inst/include/cpp11/raws.hpp +++ b/inst/include/headers/raws.hpp @@ -5,12 +5,12 @@ #include // for uint8_t #include // for initializer_list -#include "cpp11/R.hpp" // for RAW, SEXP, SEXPREC, Rf_allocVector -#include "cpp11/attribute_proxy.hpp" // for attribute_proxy -#include "cpp11/named_arg.hpp" // for named_arg -#include "cpp11/protect.hpp" // for preserved -#include "cpp11/r_vector.hpp" // for r_vector, r_vector<>::proxy -#include "cpp11/sexp.hpp" // for sexp +#include "headers/R.hpp" // for RAW, SEXP, SEXPREC, Rf_allocVector +#include "headers/attribute_proxy.hpp" // for attribute_proxy +#include "headers/named_arg.hpp" // for named_arg +#include "headers/protect.hpp" // for preserved +#include "headers/r_vector.hpp" // for r_vector, r_vector<>::proxy +#include "headers/sexp.hpp" // for sexp // Specializations for raws diff --git a/inst/include/cpp11/sexp.hpp b/inst/include/headers/sexp.hpp similarity index 90% rename from inst/include/cpp11/sexp.hpp rename to inst/include/headers/sexp.hpp index 1517c5af..c4d47ef7 100644 --- a/inst/include/cpp11/sexp.hpp +++ b/inst/include/headers/sexp.hpp @@ -4,9 +4,9 @@ #include // for string, basic_string -#include "cpp11/R.hpp" // for SEXP, SEXPREC, REAL_ELT, R_NilV... -#include "cpp11/attribute_proxy.hpp" // for attribute_proxy -#include "cpp11/protect.hpp" // for preserved +#include "headers/R.hpp" // for SEXP, SEXPREC, REAL_ELT, R_NilV... +#include "headers/attribute_proxy.hpp" // for attribute_proxy +#include "headers/protect.hpp" // for preserved namespace cpp11 { diff --git a/inst/include/cpp11/strings.hpp b/inst/include/headers/strings.hpp similarity index 90% rename from inst/include/cpp11/strings.hpp rename to inst/include/headers/strings.hpp index e312c231..886583e5 100644 --- a/inst/include/cpp11/strings.hpp +++ b/inst/include/headers/strings.hpp @@ -3,14 +3,14 @@ #include // for initializer_list #include // for string, basic_string -#include "cpp11/R.hpp" // for SEXP, TYPEOF, SEXPREC, SET_STRI... -#include "cpp11/as.hpp" // for as_sexp -#include "cpp11/attribute_proxy.hpp" // for attribute_proxy -#include "cpp11/named_arg.hpp" // for named_arg -#include "cpp11/protect.hpp" // for preserved -#include "cpp11/r_string.hpp" // for r_string -#include "cpp11/r_vector.hpp" // for r_vector, r_vector<>::proxy -#include "cpp11/sexp.hpp" // for sexp +#include "headers/R.hpp" // for SEXP, TYPEOF, SEXPREC, SET_STRI... +#include "headers/as.hpp" // for as_sexp +#include "headers/attribute_proxy.hpp" // for attribute_proxy +#include "headers/named_arg.hpp" // for named_arg +#include "headers/protect.hpp" // for preserved +#include "headers/r_string.hpp" // for r_string +#include "headers/r_vector.hpp" // for r_vector, r_vector<>::proxy +#include "headers/sexp.hpp" // for sexp // Specializations for strings diff --git a/man/cpp_source.Rd b/man/cpp_source.Rd index 87164ef5..ffe75bd2 100644 --- a/man/cpp_source.Rd +++ b/man/cpp_source.Rd @@ -68,7 +68,7 @@ external packages. This is equivalent to putting those packages in the \examples{ cpp_source( - code = '#include "cpp11/integers.hpp" + code = '#include "headers/integers.hpp" [[cpp11::register]] int num_odd(cpp11::integers x) { @@ -88,7 +88,7 @@ if (interactive() && require("progress")) { cpp_source( code = ' -#include +#include #include [[cpp11::linking_to("progress")]] diff --git a/man/cpp_vendor.Rd b/man/cpp_vendor.Rd index 857e49cf..a02f36de 100644 --- a/man/cpp_vendor.Rd +++ b/man/cpp_vendor.Rd @@ -4,10 +4,10 @@ \alias{cpp_vendor} \title{Vendor the cpp11 dependency} \usage{ -cpp_vendor(path = ".") +cpp_vendor(path = "./src/vendor") } \arguments{ -\item{path}{The path to the package root directory} +\item{path}{The path to vendor the code into.} } \value{ The file path to the vendored code (invisibly). @@ -18,11 +18,11 @@ project is using. It is often used in the go language community. } \details{ This function vendors cpp11 into your package by copying the cpp11 -headers into the \code{inst/include} folder of your package and adding -'cpp11 version: XYZ' to the top of the files, where XYZ is the version of -cpp11 currently installed on your machine. +headers into the \code{src/vendor} folder and adding 'cpp11 version: XYZ' to the +top of the files, where XYZ is the version of cpp11 currently installed on +your machine. -If you choose to vendor the headers you should \emph{remove} \code{LinkingTo: cpp11} from your DESCRIPTION. +If you choose to vendor the headers you should \emph{remove} \code{LinkingTo: cpp11} from your DESCRIPTION. This is done automatically by this function. \strong{Note}: vendoring places the responsibility of updating the code on \strong{you}. Bugfixes and new features in cpp11 will not be available for your @@ -36,7 +36,7 @@ dir.create(dir) # vendor the cpp11 headers into the directory cpp_vendor(dir) -list.files(file.path(dir, "inst", "include", "cpp11")) +list.files(file.path(dir, "src", "vendor")) # cleanup unlink(dir, recursive = TRUE) diff --git a/tests/testthat/_snaps/register.md b/tests/testthat/_snaps/register.md index 0e4b143a..75125c45 100644 --- a/tests/testthat/_snaps/register.md +++ b/tests/testthat/_snaps/register.md @@ -2,7 +2,7 @@ Code cpp_register(p, quiet = FALSE) - Message + Message i 1 functions decorated with [[cpp11::register]] v generated file 'cpp11.R' v generated file 'cpp11.cpp' diff --git a/tests/testthat/_snaps/source.md b/tests/testthat/_snaps/source.md index 15935031..ad9152aa 100644 --- a/tests/testthat/_snaps/source.md +++ b/tests/testthat/_snaps/source.md @@ -2,7 +2,8 @@ Code cpp_source(i_do_not_exist) - Error - Can't find `file` at this path: + Condition + Error: + ! Can't find `file` at this path: {NON_EXISTENT_FILEPATH} diff --git a/tests/testthat/test-register.R b/tests/testthat/test-register.R index 130abcbe..e601d69a 100644 --- a/tests/testthat/test-register.R +++ b/tests/testthat/test-register.R @@ -50,7 +50,6 @@ describe("get_call_entries", { }) it("returns an empty string for packages with .Call entries and NAMESPACE files", { - # tools::package_native_routine_registration_skeleton is not available before R 3.4 skip_if(getRversion() < "3.4") @@ -63,7 +62,8 @@ describe("get_call_entries", { expect_match(call_entries[2], "extern SEXP bar[(](void)?[)]") expect_equal( call_entries[4:7], - c("static const R_CallMethodDef CallEntries[] = {", + c( + "static const R_CallMethodDef CallEntries[] = {", " {\"bar\", (DL_FUNC) &bar, 0},", " {NULL, NULL, 0}", "};" @@ -78,12 +78,13 @@ describe("get_call_entries", { cpp_register(p) cpp_bindings <- file.path(p, "src", "cpp11.cpp") - expect_equal(read_file(cpp_bindings), - "// Generated by cpp11: do not edit by hand + expect_equal( + read_file(cpp_bindings), + "// Generated by cpp11: do not edit by hand // clang-format off -#include \"cpp11/declarations.hpp\" +#include \"headers/declarations.hpp\" #include // multiple.cpp @@ -122,7 +123,8 @@ extern \"C\" attribute_visible void R_init_testPkg(DllInfo* dll){ R_useDynamicSymbols(dll, FALSE); R_forceSymbols(dll, TRUE); } -") +" + ) }) }) @@ -236,8 +238,9 @@ describe("generate_cpp_functions", { args = list(tibble::tibble(type = character(), name = character())) ) - expect_equal(generate_cpp_functions(funs), -"// foo.cpp + expect_equal( + generate_cpp_functions(funs), + "// foo.cpp void foo(); extern \"C\" SEXP _cpp11_foo() { BEGIN_CPP11 @@ -260,8 +263,9 @@ extern \"C\" SEXP _cpp11_foo() { args = list(tibble::tibble(type = character(), name = character())) ) - expect_equal(generate_cpp_functions(funs, package = "mypkg"), -"// foo.cpp + expect_equal( + generate_cpp_functions(funs, package = "mypkg"), + "// foo.cpp void foo(); extern \"C\" SEXP _mypkg_foo() { BEGIN_CPP11 @@ -285,8 +289,9 @@ extern \"C\" SEXP _mypkg_foo() { args = list(tibble::tibble(type = character(), name = character())) ) - expect_equal(generate_cpp_functions(funs), -"// foo.cpp + expect_equal( + generate_cpp_functions(funs), + "// foo.cpp int foo(); extern \"C\" SEXP _cpp11_foo() { BEGIN_CPP11 @@ -308,8 +313,9 @@ extern \"C\" SEXP _cpp11_foo() { args = list(tibble::tibble(type = "int", name = "bar")) ) - expect_equal(generate_cpp_functions(funs), -"// foo.cpp + expect_equal( + generate_cpp_functions(funs), + "// foo.cpp void foo(int bar); extern \"C\" SEXP _cpp11_foo(SEXP bar) { BEGIN_CPP11 @@ -332,8 +338,9 @@ extern \"C\" SEXP _cpp11_foo(SEXP bar) { args = list(tibble::tibble(type = "int", name = "bar")) ) - expect_equal(generate_cpp_functions(funs), -"// foo.cpp + expect_equal( + generate_cpp_functions(funs), + "// foo.cpp int foo(int bar); extern \"C\" SEXP _cpp11_foo(SEXP bar) { BEGIN_CPP11 @@ -358,8 +365,9 @@ extern \"C\" SEXP _cpp11_foo(SEXP bar) { ) ) - expect_equal(generate_cpp_functions(funs), -"// foo.cpp + expect_equal( + generate_cpp_functions(funs), + "// foo.cpp int foo(int bar); extern \"C\" SEXP _cpp11_foo(SEXP bar) { BEGIN_CPP11 @@ -407,10 +415,12 @@ describe("generate_r_functions", { args = list(tibble::tibble(type = character(), name = character())) ) - expect_equal(generate_r_functions(funs, package = "cpp11"), -"foo <- function() { + expect_equal( + generate_r_functions(funs, package = "cpp11"), + "foo <- function() { invisible(.Call(`_cpp11_foo`)) -}") +}" + ) }) it("returns the wrapped function for a single void function with no arguments and use_package = TRUE", { @@ -425,10 +435,12 @@ describe("generate_r_functions", { args = list(tibble::tibble(type = character(), name = character())) ) - expect_equal(generate_r_functions(funs, package = "cpp11", use_package = TRUE), -"foo <- function() { + expect_equal( + generate_r_functions(funs, package = "cpp11", use_package = TRUE), + "foo <- function() { invisible(.Call(\"_cpp11_foo\", PACKAGE = \"cpp11\")) -}") +}" + ) }) it("returns the wrapped function for a single void function with no arguments and different package name", { @@ -443,10 +455,12 @@ describe("generate_r_functions", { args = list(tibble::tibble(type = character(), name = character())) ) - expect_equal(generate_r_functions(funs, package = "mypkg"), -"foo <- function() { + expect_equal( + generate_r_functions(funs, package = "mypkg"), + "foo <- function() { invisible(.Call(`_mypkg_foo`)) -}") +}" + ) }) it("returns the wrapped function for a single function with no arguments", { @@ -461,10 +475,12 @@ describe("generate_r_functions", { args = list(tibble::tibble(type = character(), name = character())) ) - expect_equal(generate_r_functions(funs, package = "cpp11"), -"foo <- function() { + expect_equal( + generate_r_functions(funs, package = "cpp11"), + "foo <- function() { .Call(`_cpp11_foo`) -}") +}" + ) }) it("returns the wrapped function for a single function with no arguments and use_package = TRUE", { @@ -479,10 +495,12 @@ describe("generate_r_functions", { args = list(tibble::tibble(type = character(), name = character())) ) - expect_equal(generate_r_functions(funs, package = "cpp11", use_package = TRUE), -"foo <- function() { + expect_equal( + generate_r_functions(funs, package = "cpp11", use_package = TRUE), + "foo <- function() { .Call(\"_cpp11_foo\", PACKAGE = \"cpp11\") -}") +}" + ) }) it("returns the wrapped function for a single void function with arguments", { @@ -497,10 +515,12 @@ describe("generate_r_functions", { args = list(tibble::tibble(type = "int", name = "bar")) ) - expect_equal(generate_r_functions(funs, package = "cpp11"), -"foo <- function(bar) { + expect_equal( + generate_r_functions(funs, package = "cpp11"), + "foo <- function(bar) { invisible(.Call(`_cpp11_foo`, bar)) -}") +}" + ) }) it("returns the wrapped function for a single function with arguments", { @@ -515,10 +535,12 @@ describe("generate_r_functions", { args = list(tibble::tibble(type = "int", name = "bar")) ) - expect_equal(generate_r_functions(funs, package = "cpp11"), -"foo <- function(bar) { + expect_equal( + generate_r_functions(funs, package = "cpp11"), + "foo <- function(bar) { .Call(`_cpp11_foo`, bar) -}") +}" + ) }) it("returns the wrapped functions for multiple functions with arguments", { @@ -536,14 +558,16 @@ describe("generate_r_functions", { ) ) - expect_equal(generate_r_functions(funs, package = "cpp11"), -"foo <- function(bar) { + expect_equal( + generate_r_functions(funs, package = "cpp11"), + "foo <- function(bar) { .Call(`_cpp11_foo`, bar) } bar <- function(baz) { .Call(`_cpp11_bar`, baz) -}") +}" + ) }) }) @@ -554,10 +578,8 @@ describe("cpp_register", { dir.create(f) expect_equal(cpp_register(f), character()) - }) it("works with a package that registers a single c++ function", { - # tools::package_native_routine_registration_skeleton is not available before R 3.4 skip_if(getRversion() < "3.4") @@ -569,21 +591,24 @@ describe("cpp_register", { r_bindings <- file.path(p, "R", "cpp11.R") expect_true(file.exists(r_bindings)) - expect_equal(read_file(r_bindings), -"# Generated by cpp11: do not edit by hand + expect_equal( + read_file(r_bindings), + "# Generated by cpp11: do not edit by hand foo <- function() { .Call(`_testPkg_foo`) } -") +" + ) cpp_bindings <- file.path(p, "src", "cpp11.cpp") expect_true(file.exists(cpp_bindings)) - expect_equal(read_file(cpp_bindings), -"// Generated by cpp11: do not edit by hand + expect_equal( + read_file(cpp_bindings), + "// Generated by cpp11: do not edit by hand // clang-format off -#include \"cpp11/declarations.hpp\" +#include \"headers/declarations.hpp\" #include // single.cpp @@ -606,7 +631,8 @@ extern \"C\" attribute_visible void R_init_testPkg(DllInfo* dll){ R_useDynamicSymbols(dll, FALSE); R_forceSymbols(dll, TRUE); } -") +" + ) }) it("can be run without messages", { diff --git a/tests/testthat/test-source.R b/tests/testthat/test-source.R index 2945d51d..3be14872 100644 --- a/tests/testthat/test-source.R +++ b/tests/testthat/test-source.R @@ -2,7 +2,7 @@ test_that("cpp_source works with the `code` parameter", { skip_on_os("solaris") dll_info <- cpp_source( code = ' - #include "cpp11/integers.hpp" + #include "headers/integers.hpp" [[cpp11::register]] int num_odd(cpp11::integers x) { @@ -14,7 +14,8 @@ test_that("cpp_source works with the `code` parameter", { } return total; } - ', clean = TRUE) + ', clean = TRUE + ) on.exit(dyn.unload(dll_info[["path"]])) expect_equal(num_odd(as.integer(c(1:10, 15, 23))), 7) @@ -28,7 +29,8 @@ test_that("cpp_source works with the `file` parameter", { bool always_true() { return true; } - ", tf) + ", tf + ) on.exit(unlink(tf)) dll_info <- cpp_source(tf, clean = TRUE, quiet = TRUE) @@ -45,7 +47,8 @@ test_that("cpp_source works with files called `cpp11.cpp`", { bool always_true() { return true; } - ", tf) + ", tf + ) on.exit(unlink(tf)) dll_info <- cpp_source(tf, clean = TRUE, quiet = TRUE) @@ -55,14 +58,16 @@ test_that("cpp_source works with files called `cpp11.cpp`", { }) test_that("cpp_source returns original file name on error", { - expect_output(try(cpp_source(test_path("single_error.cpp"), clean = TRUE), silent = TRUE), - normalizePath(test_path("single_error.cpp"), winslash = "/"), fixed = TRUE) + normalizePath(test_path("single_error.cpp"), winslash = "/"), + fixed = TRUE + ) - #error generated for incorrect attributes is separate from compilation errors + # error generated for incorrect attributes is separate from compilation errors expect_error(cpp_source(test_path("single_incorrect.cpp"), clean = TRUE), - normalizePath(test_path("single_incorrect.cpp"), winslash = "/"), fixed = TRUE) - + normalizePath(test_path("single_incorrect.cpp"), winslash = "/"), + fixed = TRUE + ) }) test_that("cpp_source lets you set the C++ standard", { @@ -77,7 +82,8 @@ test_that("cpp_source lets you set the C++ standard", { auto str = "hello_world"s; return str; } - ', tf) + ', tf + ) on.exit(unlink(tf)) dll_info <- cpp_source(tf, clean = TRUE, quiet = TRUE, cxx_std = "CXX14") @@ -97,9 +103,9 @@ test_that("generate_cpp_name works", { "foo_2.cpp" ) -expect_equal( - generate_cpp_name("foo.cpp", loaded_dlls = c("foo", "foo_2")), - "foo_3.cpp" + expect_equal( + generate_cpp_name("foo.cpp", loaded_dlls = c("foo", "foo_2")), + "foo_3.cpp" ) }) @@ -128,10 +134,12 @@ test_that("check_valid_attributes does not return an error if all registers are cpp11::writable::list x; x.push_back({"foo"_nm = 1}); return x; - }')) + }') + ) expect_error_free( - cpp11::cpp_source(clean = TRUE, - code = '#include + cpp11::cpp_source( + clean = TRUE, + code = '#include #include [[cpp11::linking_to("progress")]] @@ -145,7 +153,8 @@ test_that("check_valid_attributes does not return an error if all registers are pb.tick(); } } - ') + ' + ) ) }) @@ -164,7 +173,8 @@ test_that("check_valid_attributes returns an error if one or more registers is i cpp11::writable::list x; x.push_back({"foo"_nm = 1}); return x; - }')) + }') + ) expect_error( cpp11::cpp_source(code = '#include @@ -174,7 +184,8 @@ test_that("check_valid_attributes returns an error if one or more registers is i cpp11::writable::list x; x.push_back({"foo"_nm = 1}); return x; - }')) + }') + ) expect_error( cpp11::cpp_source(code = '#include @@ -190,14 +201,15 @@ test_that("check_valid_attributes returns an error if one or more registers is i cpp11::writable::list x; x.push_back({"foo"_nm = 1}); return x; - }')) + }') + ) expect_error( cpp11::cpp_source( code = ' - #include + #include #include [[cpp11::link_to("progress")]] [[cpp11::register]] void show_progress() { @@ -208,7 +220,9 @@ test_that("check_valid_attributes returns an error if one or more registers is i pb.tick(); } } -')) +' + ) + ) }) test_that("cpp_source(d) functions work after sourcing file more than once", { diff --git a/tests/testthat/test-vendor.R b/tests/testthat/test-vendor.R index 361c9ad9..c4a37a90 100644 --- a/tests/testthat/test-vendor.R +++ b/tests/testthat/test-vendor.R @@ -24,8 +24,8 @@ describe("cpp_vendor", { cpp_vendor(pkg_path(pkg)) - expect_true(dir.exists(file.path(p, "inst", "include", "cpp11"))) - expect_true(file.exists(file.path(p, "inst", "include", "cpp11.hpp"))) - expect_true(file.exists(file.path(p, "inst", "include", "cpp11", "declarations.hpp"))) + expect_true(dir.exists(file.path(p, "src", "vendor", "cpp11"))) + expect_true(file.exists(file.path(p, "src", "vendor", "cpp11.hpp"))) + expect_true(file.exists(file.path(p, "src", "vendor", "headers", "declarations.hpp"))) }) }) diff --git a/vignettes/FAQ.Rmd b/vignettes/FAQ.Rmd index 29d99340..05c4f3e6 100644 --- a/vignettes/FAQ.Rmd +++ b/vignettes/FAQ.Rmd @@ -455,7 +455,7 @@ set.seed(123) x <- sample(letters, 1e6, replace = TRUE) bench::mark( - test_extract_cpp11(x), + test_extract_cpp11(x), test_extract_r_api(x) ) ``` diff --git a/vignettes/converting.Rmd b/vignettes/converting.Rmd index de4b8898..16cfd2fc 100644 --- a/vignettes/converting.Rmd +++ b/vignettes/converting.Rmd @@ -26,24 +26,24 @@ It is also a place to highlight some of the largest differences between Rcpp and ## Class comparison table -| Rcpp | cpp11 (read-only) | cpp11 (writable) | cpp11 header | -| --- | --- | --- | --- | -| NumericVector | doubles | writable::doubles | | -| NumericMatrix | doubles_matrix<> | writable::doubles_matrix<> | | -| IntegerVector | integers | writable::integers | | -| IntegerMatrix | integers_matrix<> | writable::integers_matrix<> | | -| CharacterVector | strings | writable::strings | | -| RawVector | raws | writable::raws | | -| List | list | writable::list | | -| RObject | sexp | | | -| XPtr | | external_pointer | | -| Environment | | environment | | -| Function | | function | | -| Environment (namespace) | | package | | -| wrap | | as_sexp | | -| as | | as_cpp | | -| stop | stop | | | -| checkUserInterrupt | check_user_interrupt | | | +| Rcpp | cpp11 (read-only) | cpp11 (writable) | cpp11 header | +| --- | --- | --- | --- | +| NumericVector | doubles | writable::doubles | | +| NumericMatrix | doubles_matrix<> | writable::doubles_matrix<> | | +| IntegerVector | integers | writable::integers | | +| IntegerMatrix | integers_matrix<> | writable::integers_matrix<> | | +| CharacterVector | strings | writable::strings | | +| RawVector | raws | writable::raws | | +| List | list | writable::list | | +| RObject | sexp | | | +| XPtr | | external_pointer | | +| Environment | | environment | | +| Function | | function | | +| Environment (namespace) | | package | | +| wrap | | as_sexp | | +| as | | as_cpp | | +| stop | stop | | | +| checkUserInterrupt | check_user_interrupt | | | ## Incomplete list of Rcpp features not included in cpp11 @@ -99,19 +99,17 @@ Because of this you can do ~10,000,000 vector appends with cpp11 in approximatel ```{r, message = FALSE, eval = should_run_benchmarks()} library(cpp11test) -grid <- expand.grid(len = 10 ^ (0:7), pkg = "cpp11", stringsAsFactors = FALSE) +grid <- expand.grid(len = 10^(0:7), pkg = "cpp11", stringsAsFactors = FALSE) grid <- rbind( grid, - expand.grid(len = 10 ^ (0:4), pkg = "rcpp", stringsAsFactors = FALSE) + expand.grid(len = 10^(0:4), pkg = "rcpp", stringsAsFactors = FALSE) ) -b_grow <- bench::press(.grid = grid, - { - fun = match.fun(sprintf("%sgrow_", ifelse(pkg == "cpp11", "", paste0(pkg, "_")))) - bench::mark( - fun(len) - ) - } -)[c("len", "pkg", "min", "mem_alloc", "n_itr", "n_gc")] +b_grow <- bench::press(.grid = grid, { + fun <- match.fun(sprintf("%sgrow_", ifelse(pkg == "cpp11", "", paste0(pkg, "_")))) + bench::mark( + fun(len) + ) +})[c("len", "pkg", "min", "mem_alloc", "n_itr", "n_gc")] saveRDS(b_grow, "growth.Rds", version = 2) ``` @@ -186,7 +184,7 @@ You will need to include the appropriate STL header, in this case ``. ### R API includes cpp11 conflicts with macros declared by some R headers unless the macros `R_NO_REMAP` and `STRICT_R_HEADERS` are defined. -If you include `cpp11/R.hpp` before any R headers these macros will be defined appropriately, otherwise you may see errors like +If you include `headers/R.hpp` before any R headers these macros will be defined appropriately, otherwise you may see errors like > R headers were included before cpp11 headers and at least one of R_NO_REMAP or STRICT_R_HEADERS was not defined.