[Rcpp-commits] r1663 - pkg/Rcpp/inst/doc/Rcpp-sugar

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 23 12:32:35 CEST 2010


Author: romain
Date: 2010-06-23 12:32:35 +0200 (Wed, 23 Jun 2010)
New Revision: 1663

Modified:
   pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw
Log:
word on is_true, is_false, and conversion to bool

Modified: pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw	2010-06-23 10:04:55 UTC (rev 1662)
+++ pkg/Rcpp/inst/doc/Rcpp-sugar/Rcpp-sugar.Rnw	2010-06-23 10:32:35 UTC (rev 1663)
@@ -230,7 +230,7 @@
 \subsubsection{all}
 
 Given a logical sugar expression, identifies if all the elements are
-\texttt{TRUE}. This respects \proglang{R} missing values. 
+\texttt{TRUE}. 
 
 <<lang=cpp>>=
 IntegerVector x = seq_len( 1000 ) ;
@@ -248,7 +248,7 @@
 \subsubsection{any}
 
 Given a logical sugar expression, identifies if any the element is
-\texttt{TRUE}. This respects \proglang{R} missing values. 
+\texttt{TRUE}. 
 
 <<lang=cpp>>=
 IntegerVector x = seq_len( 1000 ) ;
@@ -258,6 +258,23 @@
 \texttt{any} is lazy too, so it will only need to resolve the first element
 of the example above. 
 
+\subsubsection{Conversion to bool}
+
+In order to respect the concept of missing values (\texttt{NA}) in R, 
+expressions generated by \texttt{any} or \texttt{all} can not be converted
+to \texttt{bool}. Instead one must use \texttt{is\_true}, \texttt{is\_false}
+or \texttt{is\_na}: 
+
+<<lang=cpp>>=
+// wrong: will generate a compile error
+bool res = any( x < y) ) ;
+
+// ok
+bool res = is_true( any( x < y ) )
+bool res = is_false( any( x < y ) )
+bool res = is_n	a( any( x < y ) )
+@
+
 \subsection{Functions producing sugar expressions}
 
 \subsubsection{is\_na}
@@ -642,7 +659,7 @@
     Function fun ;
 @
 
-\subsunsection{Implementation}
+\subsubsection{Implementation}
 
 The indexing operator and the \texttt{size} member function is what 
 the \texttt{VectorBase} expects. The size of the result expression is 



More information about the Rcpp-commits mailing list