@@ -87,11 +87,11 @@ vignette: >
87
87
88
88
# Getting started
89
89
90
- ## How do I get started
90
+ ## How do I get started
91
91
92
92
If you have \pkg{Rcpp} installed, please execute the following command
93
93
in \proglang{R} to access the introductory vignette (which is a
94
- variant of the \citet{JSS: Rcpp } and \citet{PeerJ: Rcpp } papers) for a
94
+ variant of the \citet{JSS: Rcpp } and \citet{PeerJ: Rcpp ,TAS : Rcpp } papers) for a
95
95
detailed introduction, ideally followed by at least the Rcpp
96
96
Attributes \citep{CRAN:Rcpp: Attributes } vignette:
97
97
@@ -104,7 +104,7 @@ vignette("Rcpp-attributes")
104
104
If you do not have \pkg{Rcpp} installed, these documents should also be available
105
105
whereever you found this document, \textsl{i.e.,} on every mirror site of CRAN.
106
106
107
- ## What do I need
107
+ ## What do I need
108
108
109
109
Obviously, \proglang{R} must be installed. \pkg{Rcpp} provides a
110
110
\proglang{C++} API as an extension to the \proglang{R} system. As such, it
@@ -125,7 +125,7 @@ means one needs:
125
125
Also see the [ RStudio documentation] ( http://www.rstudio.com/ide/docs/packages/prerequisites )
126
126
on pre-requisites for R package development.
127
127
128
- ## What compiler can I use
128
+ ## What compiler can I use
129
129
130
130
On almost all platforms, the GNU Compiler Collection (or ` gcc ` , which
131
131
is also the name of its \proglang{C} language compiler) has to be used along
@@ -250,7 +250,7 @@ Template Library to sum the elements of a numeric vector.
250
250
fx <- cxxfunction(signature(x = "numeric"),
251
251
'NumericVector xx(x);
252
252
return wrap(
253
- std::accumulate(xx.begin(),
253
+ std::accumulate(xx.begin(),
254
254
xx.end(),
255
255
0.0)
256
256
);',
@@ -277,7 +277,7 @@ the code in a character string in R. This is easily achieved by using
277
277
278
278
``` {r, eval=FALSE}
279
279
fx <- cxxfunction(signature(),
280
- paste(readLines("myfile.cpp"),
280
+ paste(readLines("myfile.cpp"),
281
281
collapse="\n"),
282
282
plugin = "Rcpp")
283
283
```
@@ -411,7 +411,7 @@ either approach takes care of a lot of these tedious and error-prone manual
411
411
steps.
412
412
413
413
414
- ## But R CMD SHLIB still does not work
414
+ ## But R CMD SHLIB still does not work
415
415
416
416
We have had reports in the past where build failures occurred when users had
417
417
non-standard code in their ` ~/.Rprofile ` or ` Rprofile.site ` (or
@@ -422,7 +422,7 @@ invocation of `Rscript -e "..."` (as in \faq{using-r-cmd-shlib}
422
422
above) to retrieve settings directly from \pkg{Rcpp} will fail.
423
423
424
424
You may need to uncomment such non-standard code, or protect it by wrapping
425
- it inside ` if (interactive()) ` , or possibly try to use
425
+ it inside ` if (interactive()) ` , or possibly try to use
426
426
` Rscript --vanilla ` instead of plain ` Rscript ` .
427
427
428
428
## What about ` LinkingTo `
@@ -688,7 +688,7 @@ will even run the R part at the end.
688
688
template <typename T> class square :
689
689
public std::unary_function<T,T> {
690
690
public:
691
- T operator()( T t) const {
691
+ T operator()( T t) const {
692
692
return t* t ;
693
693
}
694
694
};
@@ -757,7 +757,7 @@ writeLines(a, file = "myfile.cpp")
757
757
If stored in a file ` myfile.cpp ` , we can use it via \pkg{inline}:
758
758
759
759
``` {r, eval = FALSE}
760
- fx <- cxxfunction(signature(x_="numeric",
760
+ fx <- cxxfunction(signature(x_="numeric",
761
761
Y_="matrix",
762
762
z_="numeric" ),
763
763
paste(readLines("myfile.cpp"),
@@ -838,7 +838,7 @@ random variable distributed as $N(m,s)$.
838
838
Using Rcpp Attributes, this can be as simple as
839
839
840
840
``` {r, eval = FALSE}
841
- cppFunction('Rcpp::NumericVector ff(int n) {
841
+ cppFunction('Rcpp::NumericVector ff(int n) {
842
842
return rnorm(n, 0, 100); }')
843
843
set.seed(42)
844
844
ff(5)
@@ -992,10 +992,10 @@ values instead.
992
992
``` {r, eval=FALSE}
993
993
myplugin <- getPlugin("Rcpp")
994
994
myplugin$env$PKG_CXXFLAGS <- "-std=c++11"
995
- f <- cxxfunction(signature(),
995
+ f <- cxxfunction(signature(),
996
996
settings = myplugin, body = '
997
997
// fails without -std=c++0x
998
- std::vector<double> x = { 1.0, 2.0, 3.0 };
998
+ std::vector<double> x = { 1.0, 2.0, 3.0 };
999
999
return Rcpp::wrap(x);
1000
1000
')
1001
1001
f()
@@ -1025,7 +1025,7 @@ src <- '
1025
1025
x.attr("dimnames") = dimnms;
1026
1026
return(x);
1027
1027
'
1028
- fun <- cxxfunction(signature(),
1028
+ fun <- cxxfunction(signature(),
1029
1029
body=src, plugin="Rcpp")
1030
1030
fun()
1031
1031
```
@@ -1156,13 +1156,13 @@ void sample_defaults(
1156
1156
NumericVector x =
1157
1157
NumericVector::create(), // Size 0 vector
1158
1158
bool bias = true, // Set to true
1159
- std::string method =
1159
+ std::string method =
1160
1160
"rcpp rules!") { // Set string
1161
-
1161
+
1162
1162
Rcpp::Rcout << "x size: " << x.size() << ", ";
1163
1163
Rcpp::Rcout << "bias value: " << bias << ", ";
1164
1164
Rcpp::Rcout << "method value: " << ".";
1165
-
1165
+
1166
1166
}
1167
1167
1168
1168
/*** R
@@ -1212,7 +1212,7 @@ conda install gxx_linux-64
1212
1212
1213
1213
helps within this environment as it installs the corresponding
1214
1214
` x86_64-conda_cos6-linux-gnu-c++ ` compiler. Documentation for this and other
1215
- systems is provided
1215
+ systems is provided
1216
1216
[ at this page] ( https://conda.io/docs/user-guide/tasks/build-packages/compiler-tools.html ) .
1217
1217
1218
1218
# Support
@@ -1416,12 +1416,12 @@ To illustrate this phenomenon, consider the following scenario:
1416
1416
// [[Rcpp::export]]
1417
1417
Rcpp::NumericVector const_override_ex (
1418
1418
const Rcpp::NumericVector& X) {
1419
-
1419
+
1420
1420
Rcpp::NumericVector Y(X); // Create object
1421
1421
// from SEXP
1422
-
1422
+
1423
1423
Y = Y * 2; // Modify new object
1424
-
1424
+
1425
1425
return X; // Return old object
1426
1426
}
1427
1427
```
@@ -1454,10 +1454,10 @@ the aforementioned approach is emphasized:
1454
1454
// [[Rcpp::export]]
1455
1455
std::string explicit_string_conv (
1456
1456
Rcpp::CharacterVector X) {
1457
-
1457
+
1458
1458
std::string s; // define storage
1459
1459
s = X[0]; // assign from CharacterVector
1460
-
1460
+
1461
1461
return s;
1462
1462
}
1463
1463
```
@@ -1467,8 +1467,8 @@ e.g. `std::string s = X[0]`, this would result in the compiler triggering
1467
1467
a conversion error on _some_ platforms. The error would be similar to:
1468
1468
1469
1469
```{bash, eval = FALSE}
1470
- error: no viable conversion from 'Proxy'
1471
- (aka 'string_proxy<16>') to 'std::string'
1470
+ error: no viable conversion from 'Proxy'
1471
+ (aka 'string_proxy<16>') to 'std::string'
1472
1472
(aka 'basic_string<char, char_traits<char>,
1473
1473
allocator<char> >')
1474
1474
```
@@ -1501,14 +1501,14 @@ via `operator=`, then the resulting `Vector` would have a length of
1501
1501
// [[Rcpp::export]]
1502
1502
void vec_scalar_assign (int n, double fill_val) {
1503
1503
Rcpp::NumericVector X(n);
1504
- Rcpp::Rcout << "Value of Vector " <<
1505
- "on Creation: " <<
1504
+ Rcpp::Rcout << "Value of Vector " <<
1505
+ "on Creation: " <<
1506
1506
std::endl << X << std::endl;
1507
-
1507
+
1508
1508
X = fill_val;
1509
-
1509
+
1510
1510
Rcpp::Rcout << "Value of Vector " <<
1511
- "after Assignment: " <<
1511
+ "after Assignment: " <<
1512
1512
std::endl << X << std::endl;
1513
1513
}
1514
1514
```
@@ -1535,9 +1535,9 @@ void mat_scalar_assign(int n, double fill_val) {
1535
1535
Rcpp::Rcout << "Value of Matrix " <<
1536
1536
"on Creation: " <<
1537
1537
std::endl << X << std::endl;
1538
-
1538
+
1539
1539
X = fill_val;
1540
-
1540
+
1541
1541
Rcpp::Rcout << "Value of Matrix " <<
1542
1542
"after Assignment: " <<
1543
1543
std::endl << X << std::endl;
@@ -1612,7 +1612,7 @@ adequately for the majority of \pkg{Rcpp} data types. The notable exception
1612
1612
that makes what would otherwise be a universal quantifier into an existential
1613
1613
quantifier is the ` CharacterVector ` data type. Chiefly, the issue with
1614
1614
sorting strings is related to how the ` CharacterVector ` relies upon the
1615
- use of ` Rcpp::internal::string_proxy ` .
1615
+ use of ` Rcpp::internal::string_proxy ` .
1616
1616
In particular, ` Rcpp::internal::string_proxy ` is _ not_ MoveAssignable since the
1617
1617
left hand side of ` operator=(const string_proxy \&rhs) ` is _ not_
1618
1618
viewed as equivalent to the right hand side before the
@@ -1633,20 +1633,20 @@ approach alongside the problematic STL approach:
1633
1633
// [[Rcpp::export]]
1634
1634
Rcpp::CharacterVector preferred_sort (
1635
1635
Rcpp::CharacterVector x) {
1636
-
1636
+
1637
1637
Rcpp::CharacterVector y = Rcpp::clone(x);
1638
1638
y.sort();
1639
-
1639
+
1640
1640
return y;
1641
1641
}
1642
1642
1643
1643
// [[ Rcpp::export]]
1644
1644
Rcpp::CharacterVector stl_sort(
1645
1645
Rcpp::CharacterVector x) {
1646
-
1646
+
1647
1647
Rcpp::CharacterVector y = Rcpp::clone(x);
1648
1648
std::sort(y.begin(), y.end());
1649
-
1649
+
1650
1650
return y;
1651
1651
}
1652
1652
```
@@ -1699,7 +1699,7 @@ sort(x)
1699
1699
rcpp_sort(x)
1700
1700
```
1701
1701
1702
- ## Package building fails with 'symbols not found'
1702
+ ## Package building fails with 'symbols not found'
1703
1703
1704
1704
R 3.4.0 and later strongly encourage registering dynamically loadable
1705
1705
symbols. In the stronger form (where ` .registration=TRUE ` is added to the
@@ -1722,4 +1722,3 @@ elsewhere.
1722
1722
So if your autogenerated file fails, and a ` symbols not found ` error is reported
1723
1723
by the linker, consider running ` compileAttributes() ` twice. Deleting
1724
1724
` R/RcppExports.R ` and ` src/RcppExports.cpp ` may also work.
1725
-
0 commit comments