@@ -1369,7 +1369,7 @@ application binary interface (ABI), would impact the ability to reproduce
13691369pre-existing results, or require significant work. Generally speaking, these
13701370issues come to light only when pushing the edge capabilities of \pkg {Rcpp}.
13711371
1372- \subsection {Rcpp changed the (const) object I passed by value }
1372+ \subsection {\pkg { Rcpp} changed the (const) object I passed by value }
13731373
13741374\pkg {Rcpp} objects are wrappers around the underlying \Rs objects' \code {SEXP},
13751375or S-expression. The \code {SEXP} is a pointer variable that holds the location
@@ -1434,7 +1434,8 @@ from \code{seq()} or \code{a:b} reports a class of \code{"integer"} while the
14341434object is set to \code {NumericVector} or \code {NumericMatrix}. In such cases,
14351435this would lead to a new \code {SEXP} object being created behind the scenes
14361436and, thus, there would \textit {not } be a link between the \pkg {Rcpp} object
1437- and \Rs object. So, any changes in \proglang {C++} would not be propagated to \Rs unless otherwise specified.
1437+ and \Rs object. So, any changes in \proglang {C++} would not be propagated to
1438+ \Rs unless otherwise specified.
14381439
14391440<<lang =cpp >>=
14401441# include<Rcpp.h>
@@ -1461,13 +1462,31 @@ b
14611462@
14621463
14631464With this being said, there is one last area of contention with the proxy model:
1464- the keyword \code {const}. Similar to the pass by value versus pass by reference
1465- conundrum, the \code {const} declaration that indicates an object cannot be
1466- modified is just cosmetic because of the underlying \Rs semantics and data
1467- structures. There is no ability to force the appropriate \proglang {C++} behavior
1468- that traditionally governs \code {const} declarations. In some cases, the
1469- compiler may provide warnings that a \code {const} object is being modified.
1470- However, it is best to not rely upon the \code {const} keyword.
1465+ the keyword \code {const}. The \code {const} declaration indicates that an object
1466+ is not allowed to be modified by any action. Due to the way the proxy
1467+ model paradigm works, there is a way to `` override'' the \code {const} designation.
1468+ Simply put, one can create a new \pkg {Rcpp} object without the \code {const}
1469+ declaration from a pre-existing one. As a result, the new \pkg {Rcpp} object
1470+ would be allowed to be modified by the compiler and, thus, modifying the initial
1471+ \code {SEXP} object. Therefore, the initially secure \Rs object would be altered.
1472+ To illustrate this phenomenon, consider the following scenario:
1473+
1474+ <<lang =cpp >>=
1475+ # include <Rcpp.h>
1476+
1477+ // [[Rcpp :: export ]]
1478+ Rcpp :: NumericVector const_override_ex(const Rcpp :: NumericVector & X ) {
1479+ Rcpp :: NumericVector Y(X ); // Create object from SEXP
1480+ Y = Y * 2 ; // Modify new object
1481+ return X ; // Return old object
1482+ }
1483+ @
1484+
1485+ <<eval =FALSE >>=
1486+ x <- 1 : 10
1487+ const_override_ex(x )
1488+ x
1489+ @
14711490
14721491\subsection {Issues with implicit conversion from an \pkg {Rcpp} object to a scalar or
14731492other \pkg {Rcpp} object }
@@ -1514,14 +1533,14 @@ and \code{is\_false()} for \code{any()} or \code{all()}.
15141533filling element-wise }
15151534
15161535Assignment using the \code {operator=} with either \code {Vector} and
1517- \code {Matrix} classes will not illicit an element-wise fill. If you seek an
1536+ \code {Matrix} classes will not elicit an element-wise fill. If you seek an
15181537element-wise fill, then use the \code {.fill()} member method to propagate a
15191538single value throughout the object. With this being said, the behavior of
15201539\code {operator=} differs for the \code {Vector} and \code {Matrix} classes.
15211540
15221541The implementation of the \code {operator=} for the \code {Vector} class will
1523- replace the existing vector with the assignee value. This behavior is valid
1524- even if the assignee value is a scalar value such as 3.14 or 25 as the object
1542+ replace the existing vector with the assigned value. This behavior is valid
1543+ even if the assigned value is a scalar value such as 3.14 or 25 as the object
15251544is cast into the appropriate \pkg {Rcpp} object type. Therefore, if a
15261545\code {Vector} is initialized to have a length of 10 and a scalar is assigned
15271546via \code {operator=}, then the resulting \code {Vector} would have a length of
0 commit comments