Skip to content

Commit 420d1ee

Browse files
authored
Merge pull request #1167 from RcppCore/feature/faq_addition
Add FAQ entry on growing vectors
2 parents 95668a7 + 3f2ef89 commit 420d1ee

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ vignettes/Makefile
2828
vignettes/rmd
2929
\.github
3030
^issue.*\.md
31+
^note.*\.md

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2021-07-24 Dirk Eddelbuettel <[email protected]>
2+
3+
* vignettes/rmd/Rcpp-FAQ.Rmd: New entry on growing vectors
4+
15
2021-07-08 Dirk Eddelbuettel <[email protected]>
26

37
* DESCRIPTION (Version, Date): Roll minor version

vignettes/pdf/Rcpp-FAQ.pdf

2.27 KB
Binary file not shown.

vignettes/rmd/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ Rcpp-jss-2011.pdf: Rcpp-jss-2011.tex
2222
cp -vax $@ ../pdf
2323

2424
clean:
25-
@rm -rf *.aux *.log *.out *.tex *.pdf Rcpp-introduction_cache Rcpp-libraries_cache pinp.cls Rcpp-jss-2011.bbl Rcpp-jss-2011.blg auto
25+
@rm -rf *.aux *.log *.out *.toc *.tex *.pdf Rcpp-introduction_cache Rcpp-libraries_cache pinp.cls Rcpp-jss-2011.bbl Rcpp-jss-2011.blg auto

vignettes/rmd/Rcpp-FAQ.Rmd

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ bibliography: Rcpp
6161
#watermark: false
6262

6363
# Customize footer, eg by referencing the vignette
64-
footer_contents: "Rcpp Vignette"
64+
footer_contents: "Rcpp FAQ Vignette"
6565

6666
# Omit \pnasbreak at end
6767
skip_final_break: true
@@ -1775,3 +1775,32 @@ redefines `TRUE` leading to bad interactions with the `Rboolean` enum type. A
17751775
very simple solution is to be more careful and conservative with `#include`
17761776
files and a) have `#include <mach/boolean.h>` appear first and b) skip
17771777
the `#include <Rinternals.h>` as it is included by `Rcpp.h` anyway.
1778+
1779+
## Can we grow Rcpp vectors like STL vectors via 'push*'
1780+
1781+
No. Use actual STL vectors instead. This has been stated clearly many times going
1782+
back to the [original announcement in Feb 2010](https://lists.r-forge.r-project.org/pipermail/rcpp-devel/2010-February/000410.html),
1783+
StackOverflow answers in [Dec 2011](https://stackoverflow.com/a/8631853/143305)
1784+
and in [Dec 2012](https://stackoverflow.com/a/13783044/143305),
1785+
the rcpp-devel list in [Jun 2013](https://lists.r-forge.r-project.org/pipermail/rcpp-devel/2013-June/006078.html),
1786+
another StackOverflow answer in [Nov 2013](https://stackoverflow.com/a/19829440/143305),
1787+
an early Rcpp Gallery post in [Dec 2013](https://gallery.rcpp.org/articles/plyr-c-to-rcpp/),
1788+
again on StackOverflow [Dec 2014](https://stackoverflow.com/a/27585789/143305), as well as in
1789+
the 'Advanced R' [first](http://adv-r.had.co.nz/Rcpp.html#stl) and
1790+
[second](https://adv-r.hadley.nz/rcpp.html#stl) editions.
1791+
For emphasis, here is a quote from the [rcpp-devel post](https://lists.r-forge.r-project.org/pipermail/rcpp-devel/2013-June/006078.html):
1792+
1793+
> Those are somehow cosmetic additions. The usual suggestion is not to
1794+
> use push_front and push_back on Rcpp types.
1795+
>
1796+
> We use R's memory, and in R, resizing a vector means moving the data.
1797+
> So if you push_back 3 times, you're moving the data 3 times.
1798+
>
1799+
> Using R own memory is the best ever decision we made in Rcpp. You can
1800+
> always use your own data structures to accumulate data, perhaps using
1801+
> stl types and then convert back to R types, which is something we make
1802+
> easy to do.
1803+
1804+
Many code examples and packages show exactly that approach (as _e.g._ discussed
1805+
in the [Rcpp Gallery post](https://gallery.rcpp.org/articles/plyr-c-to-rcpp/)).
1806+
Anybody who claims otherwise is (possibly intentionally) misleading.

0 commit comments

Comments
 (0)