[Rprotobuf-commits] r770 - pkg/vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jan 13 23:03:09 CET 2014


Author: murray
Date: 2014-01-13 23:03:09 +0100 (Mon, 13 Jan 2014)
New Revision: 770

Modified:
   pkg/vignettes/RProtoBuf-intro.Rnw
Log:
Hard code output of Sweave on a 64-bit platform for the int64 section,
as there is no good way to conditionally influence the sweaving and we
still need to show 32-bit users what they are missing out on.



Modified: pkg/vignettes/RProtoBuf-intro.Rnw
===================================================================
--- pkg/vignettes/RProtoBuf-intro.Rnw	2014-01-13 21:30:55 UTC (rev 769)
+++ pkg/vignettes/RProtoBuf-intro.Rnw	2014-01-13 22:03:09 UTC (rev 770)
@@ -2054,23 +2054,40 @@
 If we try to set an int64 field in R to double values, we lose
 precision:
 
-<<>>=
-if (.Machine$sizeof.longlong >= 8) {
-  test <- new(protobuf_unittest.TestAllTypes)
-  test$repeated_int64 <- c(2^53, 2^53+1)
-  length(unique(test$repeated_int64))
-}
-@
+% We comment out the raw Sweave here because it doesn't work on 32-bit
+% platforms but it is important to illustrate what the user is missing
+% out on so we hard code the output from a platform with 64-bit long
+% long type.
+%
+% <<>>=
+%  test <- new(protobuf_unittest.TestAllTypes)
+%  test$repeated_int64 <- c(2^53, 2^53+1)
+%  length(unique(test$repeated_int64))
+% @
 
+\begin{Schunk}
+\begin{Sinput}
+>   test <- new(protobuf_unittest.TestAllTypes)
+>   test$repeated_int64 <- c(2^53, 2^53+1)
+>   length(unique(test$repeated_int64))
+\end{Sinput}
+\begin{Soutput}
+[1] 1
+\end{Soutput}
+\end{Schunk}
+
 However, we can specify the values as character strings so that the
 C++ library on which RProtoBuf is based can store a true 64-bit
 integer representation of the data.
 
-<<>>=
-if (.Machine$sizeof.longlong >= 8) {
-  test$repeated_int64 <- c("9007199254740992", "9007199254740993")
-}
-@
+% <<>>=
+%   test$repeated_int64 <- c("9007199254740992", "9007199254740993")
+% @
+\begin{Schunk}
+\begin{Sinput}
+>   test$repeated_int64 <- c("9007199254740992", "9007199254740993")
+\end{Sinput}
+\end{Schunk}
 
 When reading the value back into R, numeric types are returned by
 default, but when the full precision is required a character value
@@ -2081,16 +2098,54 @@
 % output inside the block (E.g. the output of test$repeated_int64).
 % This reduces the usefulness of this example when we are on a 64-bit
 % platform.  E.g. only the final ``2'' is returned.
-<<echo=TRUE,print=TRUE>>=
-if (.Machine$sizeof.longlong >= 8) {
-  options("RProtoBuf.int64AsString" = FALSE)
-  test$repeated_int64
-  length(unique(test$repeated_int64))
-  options("RProtoBuf.int64AsString" = TRUE)
-  test$repeated_int64
-  length(unique(test$repeated_int64))
-}
-@
+% <<echo=TRUE,print=TRUE>>=
+%  options("RProtoBuf.int64AsString" = FALSE)
+%  test$repeated_int64
+%  length(unique(test$repeated_int64))
+%  options("RProtoBuf.int64AsString" = TRUE)
+%  test$repeated_int64
+%  length(unique(test$repeated_int64))
+%@
+\begin{Schunk}
+\begin{Sinput}
+>   options("RProtoBuf.int64AsString" = FALSE)
+\end{Sinput}
+\begin{Soutput}
+$RProtoBuf.int64AsString
+[1] FALSE
+\end{Soutput}
+\begin{Sinput}
+>   test$repeated_int64
+\end{Sinput}
+\begin{Soutput}
+[1] 9.007199e+15 9.007199e+15
+\end{Soutput}
+\begin{Sinput}
+>   length(unique(test$repeated_int64))
+\end{Sinput}
+\begin{Soutput}
+[1] 1
+\end{Soutput}
+\begin{Sinput}
+>   options("RProtoBuf.int64AsString" = TRUE)
+\end{Sinput}
+\begin{Soutput}
+$RProtoBuf.int64AsString
+[1] FALSE
+\end{Soutput}
+\begin{Sinput}
+>   test$repeated_int64
+\end{Sinput}
+\begin{Soutput}
+[1] "9007199254740992" "9007199254740993"
+\end{Soutput}
+\begin{Sinput}
+>   length(unique(test$repeated_int64))
+\end{Sinput}
+\begin{Soutput}
+[1] 2
+\end{Soutput}
+\end{Schunk}
 
 <<echo=FALSE,print=FALSE>>=
 options("RProtoBuf.int64AsString" = FALSE)



More information about the Rprotobuf-commits mailing list