Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
b1d8ecd
implement #312
pachadotdev Feb 1, 2025
7a72ec9
implement fix for #445
pachadotdev May 9, 2025
fcb7756
only one cstdlib in data_frame.hpp
pachadotdev May 9, 2025
012e4e0
use inline constexpr for doubles/integers/list/logicals/strings
pachadotdev May 9, 2025
2be6542
use noexcept in protect/sexp
pachadotdev May 9, 2025
91c3bd4
noexcept in operator SEXP (attribute proxy)
pachadotdev May 9, 2025
472f40f
+ noexcept
pachadotdev May 9, 2025
4209cf0
clang format
pachadotdev May 9, 2025
b0b3f47
rollback noexcept
pachadotdev May 9, 2025
8fdaaef
clang format
pachadotdev May 9, 2025
a80ae91
fix typos
pachadotdev May 9, 2025
ff8e314
fix r_Vector
pachadotdev May 9, 2025
f7fd0e0
fix strings
pachadotdev May 9, 2025
e0229d5
rollback strings
pachadotdev May 9, 2025
ddf5300
rollback strings
pachadotdev May 9, 2025
9851423
use a lamba to unwind protect around the loop
pachadotdev Aug 26, 2025
c016918
Use values added to a vector with push_back immediately
pachadotdev Aug 26, 2025
8ee112a
fix clang format
pachadotdev Aug 26, 2025
8093e12
llvm formatt
pachadotdev Sep 7, 2025
6783944
Global symbol visibility
pachadotdev Sep 15, 2025
5114411
clang ofrmat
pachadotdev Sep 15, 2025
acdcf61
clang format
pachadotdev Sep 15, 2025
e340f78
clang format 12
pachadotdev Sep 15, 2025
3c6e5c6
clang fmt
pachadotdev Sep 15, 2025
224b9af
check unix tests
pachadotdev Sep 15, 2025
c9def8e
roxygen: restore roxygen unit tests and helpers (single commit)
pachadotdev Sep 18, 2025
00bd129
Correctly set dimnames for matrices
pachadotdev Sep 18, 2025
b138ff8
ordered and unordered C++ maps are converted to R lists - replaces #437
pachadotdev Sep 18, 2025
96ac5e2
remove roxygen changes, that is a different PR
pachadotdev Sep 18, 2025
11ac825
copy complex numbers/vectors/matrices from R to C++ and viceversa - r…
pachadotdev Sep 18, 2025
d9a03d3
almost there
pachadotdev Sep 18, 2025
9662aa7
fix cplx len
pachadotdev Sep 18, 2025
fe2bf32
simplify three false conditions for r_vector string (fix #431)
pachadotdev Sep 19, 2025
fc83025
Using vmaxget/vmaxset for as_cpp (implement #432)
pachadotdev Sep 19, 2025
fa90fd5
clang format
pachadotdev Sep 19, 2025
4decce7
Merge pull request #24 from pachadotdev/map-to-list-clean
pachadotdev Sep 29, 2025
015c9e6
Merge pull request #25 from pachadotdev/3Fto1T-clean
pachadotdev Sep 29, 2025
c42a61e
Merge pull request #26 from pachadotdev/vmaxgetset-clean
pachadotdev Sep 29, 2025
b03d10f
Merge pull request #27 from pachadotdev/matrix_attr-clean
pachadotdev Sep 29, 2025
badd2f0
Merge pull request #28 from pachadotdev/issue452
pachadotdev Sep 29, 2025
cbdd514
Merge pull request #29 from pachadotdev/issue453
pachadotdev Sep 29, 2025
fb955fd
Merge pull request #30 from pachadotdev/compilationspeed
pachadotdev Sep 29, 2025
547a7bb
Merge branch 'pacha' into nullable_extptr
pachadotdev Sep 29, 2025
6d8426c
named_arg check with minimal changes
pachadotdev Sep 29, 2025
6739ade
Merge pull request #36 from pachadotdev/named_arg_utf8-clean
pachadotdev Nov 11, 2025
21e343b
Merge pull request #37 from pachadotdev/vmaxgetset-clean
pachadotdev Nov 11, 2025
3e1116e
Merge pull request #38 from pachadotdev/3Fto1T-clean
pachadotdev Nov 11, 2025
37e83e0
Merge branch 'cpp11-to-cpp4r' into complex-lean
pachadotdev Nov 11, 2025
933f214
Merge pull request #39 from pachadotdev/complex-lean
pachadotdev Nov 11, 2025
b7ce3ec
Merge branch 'cpp11-to-cpp4r' into map-to-list-clean
pachadotdev Nov 11, 2025
c8ce428
Merge pull request #40 from pachadotdev/map-to-list-clean
pachadotdev Nov 11, 2025
9b14d56
Merge branch 'cpp11-to-cpp4r' into matrix_attr-clean
pachadotdev Nov 11, 2025
37dd86c
Merge pull request #41 from pachadotdev/matrix_attr-clean
pachadotdev Nov 11, 2025
6beb3de
Merge pull request #42 from pachadotdev/issue452
pachadotdev Nov 11, 2025
3db9407
Merge pull request #43 from pachadotdev/issue453
pachadotdev Nov 11, 2025
fbe1468
Merge branch 'cpp11-to-cpp4r' into nullable_extptr
pachadotdev Nov 11, 2025
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
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ all:
@Rscript -e 'devtools::load_all("cpp11test")'
@echo "make: Leaving directory 'cpp11test/src'"

install:
@Rscript -e 'devtools::document()'
@Rscript -e 'devtools::install()'

test: all
@echo "make: Entering directory 'cpp11test/tests/testthat'"
@echo "make: Entering directory 'cpp11test'"
@Rscript -e 'devtools::document("cpp11test")'
@Rscript -e 'devtools::test("cpp11test")'
@echo "make: Leaving directory 'cpp11test/tests/testthat'"

Expand Down
21 changes: 15 additions & 6 deletions R/source.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
#' uses 'CXX11' if unset.
#' @param dir The directory to store the generated source files. `tempfile()` is
#' used by default. The directory will be removed if `clean` is `TRUE`.
#' @param local Passed to [dyn.load()]. If `TRUE` (the default) the shared
#' library is loaded with local symbols; if `FALSE` symbols are made global
#' (equivalent to `dyn.load(..., local = FALSE)`), which can be required when
#' other shared objects need to see RTTI/vtable symbols from this library.
#' @note See the unit test that demonstrates this usage at
#' \code{tests/testthat/test-source-local.R} (shows how `local = FALSE` exports
#' the necessary symbols so separate shared objects can link against them).
#' @return For [cpp_source()] and `[cpp_function()]` the results of
#' [dyn.load()] (invisibly). For `[cpp_eval()]` the results of the evaluated
#' expression.
Expand Down Expand Up @@ -65,7 +72,7 @@
#' }
#'
#' @export
cpp_source <- function(file, code = NULL, env = parent.frame(), clean = TRUE, quiet = TRUE, cxx_std = Sys.getenv("CXX_STD", "CXX11"), dir = tempfile()) {
cpp_source <- function(file, code = NULL, env = parent.frame(), clean = TRUE, quiet = TRUE, cxx_std = Sys.getenv("CXX_STD", "CXX11"), dir = tempfile(), local = TRUE) {
stop_unless_installed(c("brio", "callr", "cli", "decor", "desc", "glue", "tibble", "vctrs"))
if (!missing(file) && !file.exists(file)) {
stop("Can't find `file` at this path:\n", file, "\n", call. = FALSE)
Expand Down Expand Up @@ -145,7 +152,7 @@ cpp_source <- function(file, code = NULL, env = parent.frame(), clean = TRUE, qu
brio::write_lines(r_functions, r_path)
source(r_path, local = env)

dyn.load(shared_lib, local = TRUE, now = TRUE)
dyn.load(shared_lib, local = local, now = TRUE)
}

the <- new.env(parent = emptyenv())
Expand Down Expand Up @@ -183,7 +190,7 @@ 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_function <- function(code, env = parent.frame(), clean = TRUE, quiet = TRUE, cxx_std = Sys.getenv("CXX_STD", "CXX11"), local = TRUE) {
cpp_source(code = paste(c('#include "cpp11.hpp"',
"using namespace ::cpp11;",
"namespace writable = ::cpp11::writable;",
Expand All @@ -193,15 +200,16 @@ cpp_function <- function(code, env = parent.frame(), clean = TRUE, quiet = TRUE,
env = env,
clean = clean,
quiet = quiet,
cxx_std = cxx_std
cxx_std = cxx_std,
local = local
)
}

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_eval <- function(code, env = parent.frame(), clean = TRUE, quiet = TRUE, cxx_std = Sys.getenv("CXX_STD", "CXX11"), local = TRUE) {
cpp_source(code = paste(c('#include "cpp11.hpp"',
"using namespace ::cpp11;",
"namespace writable = ::cpp11::writable;",
Expand All @@ -214,7 +222,8 @@ cpp_eval <- function(code, env = parent.frame(), clean = TRUE, quiet = TRUE, cxx
env = env,
clean = clean,
quiet = quiet,
cxx_std = cxx_std
cxx_std = cxx_std,
local = local
)
f()
}
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,13 @@ Please note that the cpp11 project is released with a [Contributor Code of Condu

cpp11 would not exist without Rcpp.
Thanks to the Rcpp authors, Dirk Eddelbuettel, Romain Francois, JJ Allaire, Kevin Ushey, Qiang Kou, Nathan Russell, Douglas Bates and John Chambers for their work writing and maintaining Rcpp.

## Clang format

To match GHA, use clang-format-12 to format C++ code. With systems that provide clang-format-14 or newer, you can use Docker:

```bash
docker run --rm -v "$PWD":/work -w /work ubuntu:22.04 bash -lc "\
apt-get update && apt-get install -y clang-format-12 && \
find . -name '*.cpp' -o -name '*.hpp' -o -name '*.h' | xargs -r clang-format-12 -i"
```
2 changes: 1 addition & 1 deletion cpp11test/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ Suggests:
xml2
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
RoxygenNote: 7.3.2
68 changes: 68 additions & 0 deletions cpp11test/R/cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,22 @@ grow_ <- function(n) {
.Call(`_cpp11test_grow_`, n)
}

grow_cplx_ <- function(n) {
.Call(`_cpp11test_grow_cplx_`, n)
}

cpp11_insert_ <- function(num_sxp) {
.Call(`_cpp11test_cpp11_insert_`, num_sxp)
}

ordered_map_to_list_ <- function(x) {
.Call(`_cpp11test_ordered_map_to_list_`, x)
}

unordered_map_to_list_ <- function(x) {
.Call(`_cpp11test_unordered_map_to_list_`, x)
}

gibbs_cpp <- function(N, thin) {
.Call(`_cpp11test_gibbs_cpp`, N, thin)
}
Expand All @@ -108,6 +120,18 @@ row_sums <- function(x) {
.Call(`_cpp11test_row_sums`, x)
}

mat_mat_copy_dimnames <- function(x) {
.Call(`_cpp11test_mat_mat_copy_dimnames`, x)
}

mat_sexp_copy_dimnames <- function(x) {
.Call(`_cpp11test_mat_sexp_copy_dimnames`, x)
}

mat_mat_create_dimnames <- function() {
.Call(`_cpp11test_mat_mat_create_dimnames`)
}

col_sums <- function(x) {
.Call(`_cpp11test_col_sums`, x)
}
Expand Down Expand Up @@ -196,6 +220,42 @@ sum_dbl_accumulate2_ <- function(x_sxp) {
.Call(`_cpp11test_sum_dbl_accumulate2_`, x_sxp)
}

sum_cplx_for_ <- function(x) {
.Call(`_cpp11test_sum_cplx_for_`, x)
}

sum_cplx_for_2_ <- function(x) {
.Call(`_cpp11test_sum_cplx_for_2_`, x)
}

sum_cplx_for_3_ <- function(x_sxp) {
.Call(`_cpp11test_sum_cplx_for_3_`, x_sxp)
}

sum_cplx_for_4_ <- function(x_sxp) {
.Call(`_cpp11test_sum_cplx_for_4_`, x_sxp)
}

sum_cplx_for_5_ <- function(x_sxp) {
.Call(`_cpp11test_sum_cplx_for_5_`, x_sxp)
}

sum_cplx_for_6_ <- function(x_sxp) {
.Call(`_cpp11test_sum_cplx_for_6_`, x_sxp)
}

sum_cplx_foreach_ <- function(x) {
.Call(`_cpp11test_sum_cplx_foreach_`, x)
}

sum_cplx_accumulate_ <- function(x) {
.Call(`_cpp11test_sum_cplx_accumulate_`, x)
}

sum_cplx_for2_ <- function(x_sxp) {
.Call(`_cpp11test_sum_cplx_for2_`, x_sxp)
}

sum_int_for_ <- function(x) {
.Call(`_cpp11test_sum_int_for_`, x)
}
Expand Down Expand Up @@ -236,6 +296,14 @@ rcpp_push_and_truncate_ <- function(size_sxp) {
.Call(`_cpp11test_rcpp_push_and_truncate_`, size_sxp)
}

nullable_extptr_1 <- function() {
.Call(`_cpp11test_nullable_extptr_1`)
}

nullable_extptr_2 <- function() {
.Call(`_cpp11test_nullable_extptr_2`)
}

test_destruction_inner <- function() {
invisible(.Call(`_cpp11test_test_destruction_inner`))
}
Expand Down
Loading
Loading