Skip to content

Commit d91ddb0

Browse files
committed
fix copy constructors for C++ 11/14 / ammend RNG note / partial int-dbl-lgl matrix implict conversion
1 parent 3368d63 commit d91ddb0

File tree

120 files changed

+12127
-214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+12127
-214
lines changed

.github/workflows/test-coverage.yaml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,33 @@ jobs:
3434
run: |
3535
options(warn = 2)
3636
pak::local_install("./", dependencies = TRUE)
37+
38+
# Override Makevars to avoid _FORTIFY_SOURCE warning with -O0
39+
# covr adds --coverage which needs -O0, but _FORTIFY_SOURCE needs -O
40+
makevars_content <- paste(
41+
"PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)",
42+
"PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)",
43+
sep = "\n"
44+
)
45+
writeLines(makevars_content, "./extended-tests/cpp4rtest/src/Makevars")
46+
3747
pak::local_install("./extended-tests/cpp4rtest", dependencies = TRUE)
3848
shell: Rscript {0}
3949

4050
- name: Test coverage
4151
run: |
42-
coverage <- covr::package_coverage("./extended-tests/cpp4rtest", quiet = FALSE)
43-
percent <- round(covr::percent_coverage(coverage))
44-
cat("Coverage:", percent, "%\n")
52+
coverage <- covr::package_coverage(
53+
"./extended-tests/cpp4rtest",
54+
type = "all",
55+
quiet = FALSE
56+
)
57+
58+
# Debug: show coverage breakdown
59+
print(coverage)
60+
61+
percent_exact <- covr::percent_coverage(coverage)
62+
percent <- floor(percent_exact) # Use floor for conservative estimate
63+
cat("\nCoverage:", percent_exact, "% (rounded down to", percent, "%)\n")
4564
4665
# Create badge color based on coverage
4766
if (percent >= 90) {

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ check:
2121
@$(MAKE) install
2222
@$(MAKE) register
2323
@Rscript -e 'devtools::check("./", error_on = "error")'
24-
@Rscript -e 'cpp4r::register("extended-tests/cpp4rtest")'
25-
@Rscript -e 'devtools::check("./", error_on = "error")'
2624
@echo "==============================="
2725
@echo "Checking C++ code"
2826
@$(MAKE) install
2927
@rm -f extended-tests-results/*.log
3028
@rm -f extended-tests-results/check-results.md
29+
@Rscript -e 'cpp4r::register("extended-tests/cpp4rtest")'
3130
@export -p USE_CLANG; /bin/bash -euo pipefail -c './scripts/check_loop.sh'
3231
@echo "==============================="
3332

docs/last-updated.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"last_updated": "Last updated: 2025-11-29 20:43:17"
2+
"last_updated": "Last updated: 2025-11-30 09:25:47"
33
}

docs/search.json

Lines changed: 6 additions & 6 deletions
Large diffs are not rendered by default.

docs/vignettes/08-logical-functions-2.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,6 @@ <h2>Are all values in a vector ‘true’?</h2>
260260
all2_cpp_3(x &gt; 2)
261261
)</code></pre>
262262
</div>
263-
<div id="references" class="section level2">
264-
<h2>References</h2>
265-
</div>
266263

267264

268265

docs/vignettes/09-rolling-functions-2.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,6 @@ <h2>Cumulative maximum</h2>
286286
cummax_cpp(x)
287287
)</code></pre>
288288
</div>
289-
<div id="references" class="section level2">
290-
<h2>References</h2>
291-
</div>
292289

293290

294291

docs/vignettes/10-statistical-functions-2.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,6 @@ <h2>Root Mean Square Error (RMSE)</h2>
249249
rmse2_cpp(x, 0, na_rm = TRUE)
250250
)</code></pre>
251251
</div>
252-
<div id="references" class="section level2">
253-
<h2>References</h2>
254-
</div>
255252

256253

257254

docs/vignettes/12-external-pointers.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ <h1></h1>
9797
return ptr;</code></pre>
9898
<p>Similarly, the <code>Rcpp</code> version checks the engine with:</p>
9999
<pre class="r"><code>stopifnot(inherits(engine, "tesseract"))</code></pre>
100-
<div id="references" class="section level2">
101-
<h2>References</h2>
102-
</div>
103100

104101

105102

docs/vignettes/13-compiler-optimization.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,6 @@ <h2>Anticonf scripts</h2>
193193
optimization level used by R. It also serves the goal of testing that a
194194
simple file can be compiled.</p>
195195
</div>
196-
<div id="references" class="section level2">
197-
<h2>References</h2>
198-
</div>
199196

200197

201198

docs/vignettes/16-FAQ.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,26 @@ <h2>How do I modify a matrix rownames/colnames on C++ side?</h2>
692692
return out;
693693
}</code></pre>
694694
</div>
695+
<div id="how-do-i-use-the-same-seed-defined-in-r-for-random-number-generation-in-c" class="section level2">
696+
<h2>How do I use the same seed defined in R for random number generation
697+
in C++?</h2>
698+
<p>If you use <code>set.seed(42)</code> (or any other value) in R, you
699+
need to explicitly use <code>GetRNGstate()</code> and
700+
<code>PutRNGstate()</code> in your C++ code to synchronize the RNG state
701+
between R and C++. Otherwise, the result will not be replicable for not
702+
correctly using the Random Number Generator (RNG) state from R.</p>
703+
<pre class="cpp"><code>#include "cpp4r/doubles.hpp"
704+
#include "R.h"
705+
#include "Rmath.h"
706+
707+
// single draw from standard normal using R's RNG (replicable result)
708+
[[cpp4r::register]] double using_rng_() {
709+
GetRNGstate();
710+
double x = Rf_rnorm(0, 1);
711+
PutRNGstate();
712+
return x;
713+
}</code></pre>
714+
</div>
695715

696716

697717

0 commit comments

Comments
 (0)