[Rcpp-commits] r3952 - in pkg/Rcpp/inst/doc: . Rcpp-attributes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Nov 13 04:06:42 CET 2012


Author: jjallaire
Date: 2012-11-13 04:06:34 +0100 (Tue, 13 Nov 2012)
New Revision: 3952

Modified:
   pkg/Rcpp/inst/doc/Makefile
   pkg/Rcpp/inst/doc/Rcpp-attributes/Rcpp-attributes.Rnw
Log:
add highlights macros and remove latex highlighting sweave driver from the makefile

Modified: pkg/Rcpp/inst/doc/Makefile
===================================================================
--- pkg/Rcpp/inst/doc/Makefile	2012-11-13 02:50:31 UTC (rev 3951)
+++ pkg/Rcpp/inst/doc/Makefile	2012-11-13 03:06:34 UTC (rev 3952)
@@ -141,7 +141,7 @@
 
 Rcpp-attributes.pdf : Rcpp-attributes/Rcpp-attributes.Rnw
 	cp -f Rcpp-attributes/Rcpp-attributes.Rnw .
-	$(RSCRIPT) --vanilla -e "require(highlight); driver <- HighlightWeaveLatex(boxes = TRUE, bg = 'white' ); Sweave( 'Rcpp-attributes.Rnw', driver = driver ); "
+	$(RSCRIPT) --vanilla -e "Sweave( 'Rcpp-attributes.Rnw' );"
 	$(RSCRIPT) --vanilla -e "tools::texi2dvi( 'Rcpp-attributes.tex', pdf = TRUE, clean = FALSE )"
 	bibtex Rcpp-attributes
 ifneq (,$(findstring edd,$(whoami)))

Modified: pkg/Rcpp/inst/doc/Rcpp-attributes/Rcpp-attributes.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-attributes/Rcpp-attributes.Rnw	2012-11-13 02:50:31 UTC (rev 3951)
+++ pkg/Rcpp/inst/doc/Rcpp-attributes/Rcpp-attributes.Rnw	2012-11-13 03:06:34 UTC (rev 3952)
@@ -22,9 +22,6 @@
 \newcommand{\ith}{\textsl{i}-\textsuperscript{th}}
 \newcommand{\code}[1]{\texttt{#1}}
 
-\DefineVerbatimEnvironment{code}{Verbatim}{xrightmargin=2em,
-                                           frame=single}
-
 <<echo=FALSE,print=FALSE>>=
 prettyVersion <- packageDescription("Rcpp")$Version
 prettyDate <- format(Sys.Date(), "%B %e, %Y")
@@ -34,6 +31,29 @@
 \title{\pkg{Rcpp} Attributes}
 \date{\pkg{Rcpp} version \Sexpr{prettyVersion} as of \Sexpr{prettyDate}}
 
+%% highlights macros
+%% Style definition file generated by highlight 2.7, http://www.andre-simon.de/
+% Highlighting theme definition:
+\newcommand{\hlstd}[1]{\textcolor[rgb]{0,0,0}{#1}}
+\newcommand{\hlnum}[1]{\textcolor[rgb]{0,0,0}{#1}}
+\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}
+\newcommand{\hlesc}[1]{\textcolor[rgb]{0.74,0.55,0.55}{#1}}
+%\newcommand{\hlstr}[1]{\textcolor[rgb]{0.74,0.55,0.55}{#1}}
+\newcommand{\hlstr}[1]{\textcolor[rgb]{0.90,0.15,0.15}{#1}}
+%green: \newcommand{\hlstr}[1]{\textcolor[rgb]{0.13,0.67,0.13}{#1}} % 0.74 -> % 0.90; 0.55 -> 0.25
+\newcommand{\hldstr}[1]{\textcolor[rgb]{0.74,0.55,0.55}{#1}}
+\newcommand{\hlslc}[1]{\textcolor[rgb]{0.67,0.13,0.13}{\it{#1}}}
+\newcommand{\hlcom}[1]{\textcolor[rgb]{0.67,0.13,0.13}{\it{#1}}}
+\newcommand{\hldir}[1]{\textcolor[rgb]{0,0,0}{#1}}
+\newcommand{\hlsym}[1]{\textcolor[rgb]{0,0,0}{#1}}
+\newcommand{\hlline}[1]{\textcolor[rgb]{0.33,0.33,0.33}{#1}}
+\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.61,0.13,0.93}{\bf{#1}}}
+\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.13,0.54,0.13}{#1}}
+\newcommand{\hlkwc}[1]{\textcolor[rgb]{0,0,1}{#1}}
+\newcommand{\hlkwd}[1]{\textcolor[rgb]{0,0,0}{#1}}
+\definecolor{bgcolor}{rgb}{1,1,1}
+
+
 \begin{document}
 \maketitle
 
@@ -105,7 +125,7 @@
 contains an implementation of convolve (note the \texttt{Rcpp::export}
 attribute in the comment above the function):
 
-\begin{code}
+\begin{verbatim}
 #include <Rcpp.h>
 using namespace Rcpp;
 
@@ -122,16 +142,16 @@
 
     return xab;
 }
-\end{code}
+\end{verbatim}
 
 
 The addition of the export attribute allows us to do this from the \proglang{R}
 prompt:
 
-\begin{code}
+\begin{verbatim}
 > sourceCpp("convolve.cpp")
 > convolveCpp(x, y)
-\end{code}
+\end{verbatim}
 
 
 We can now write \proglang{C++} functions using standard \proglang{C++} types
@@ -144,10 +164,10 @@
 adding a name parameter to \texttt{Rcpp::export}. For example the
 following will export \texttt{convolveCpp} as a hidden \proglang{R} function:
 
-\begin{code}
+\begin{verbatim}
 // [[Rcpp::export(".convolveCpp")]]
 NumericVector convolveCpp(NumericVector a, NumericVector b)
-\end{code}
+\end{verbatim}
 
 The \texttt{sourceCpp} function performs caching based on the last
 modified date of the source file so as long as the source file does not
@@ -160,7 +180,7 @@
 It's also possible to use the \texttt{Rcpp::depends} attribute to declare
 dependencies on other packages. For example:
 
-\begin{code}
+\begin{verbatim}
 // [[Rcpp::depends(RcppArmadillo)]]
 
 #include <RcppArmadillo.h>
@@ -184,16 +204,16 @@
     return List::create(Named("coefficients") = coef,
                         Named("stderr")       = stderrest);
 }
-\end{code}
+\end{verbatim}
 
 The inclusion of the \texttt{Rcpp::depends} attribute causes \texttt{sourceCpp} 
 to configure the build environment to correctly compile and link against the
 \pkg{RcppArmadillo} package. Source files can declare more than one dependency 
 either by using multiple \texttt{Rcpp::depends} attributes or with syntax like this:
 
-\begin{code}
+\begin{verbatim}
 // [[Rcpp::depends(Matrix, RcppArmadillo)]]
-\end{code}
+\end{verbatim}
 
 Dependencies are discovered both by scanning for package include directories 
 and by invoking \pkg{inline} plugins if they are available for a package.
@@ -209,7 +229,7 @@
 by either passing a code string to \texttt{sourceCpp} or using the shorter-form
 \texttt{cppFunction} or \texttt{evalCpp} functions. For example:
 
-\begin{code}
+\begin{verbatim}
 > cppFunction('
     int fibonacci(const int x) {
         if (x < 2)
@@ -220,13 +240,13 @@
 ')
 
 > evalCpp('std::numeric_limits<double>::max()')
-\end{code}
+\end{verbatim}
 
 You can also specify a depends parameter to \texttt{cppFunction} or \texttt{evalCpp}:
 
-\begin{code}
+\begin{verbatim}
 > cppFunction(depends = 'RcppArmadillo', code = '...')
-\end{code}
+\end{verbatim}
 
 Note that using \texttt{sourceCpp}, \texttt{cppFunction}, and \texttt{evalCpp} 
 require that \proglang{C++} development tools be available to build the code. 
@@ -246,9 +266,9 @@
 
 For example, executing this from within the package working directory:
 
-\begin{code}
+\begin{verbatim}
 > compileAttributes()
-\end{code}
+\end{verbatim}
 
 Results in the generation of the following two source files:
 
@@ -270,9 +290,9 @@
 \proglang{C++} functions directly to users of your package. For example, the following 
 specifies that both R and \proglang{C++} interfaces should be generated:
 
-\begin{code}
+\begin{verbatim}
 // [[Rcpp::interfaces(r, cpp)]]
-\end{code}
+\end{verbatim}
 
 The \texttt{Rcpp::interfaces} attribute is specified on a per-source file basis. 
 If you request a \texttt{cpp} interface for a source file then \texttt{compileAttributes} 
@@ -296,7 +316,7 @@
 For example, an exported \proglang{C++} function \texttt{bar} could be called from
 package \texttt{MyPackage} as follows:
 
-\begin{code}
+\begin{verbatim}
 // [[Rcpp::depends(MyPackage)]]
 
 #include <MyPackage.h>
@@ -304,7 +324,7 @@
 void foo() {
     MyPackage::bar();
 }
-\end{code}
+\end{verbatim}
 
 Note that the default behavior if an \texttt{Rcpp::interfaces} attribute
 is not included in a source file is to generate an R interface only.
@@ -322,24 +342,24 @@
 into R roxygen comments within \texttt{R/RcppExports.R}. For example the
 following code in a \proglang{C++} source file:
 
-\begin{code}
+\begin{verbatim}
 //' The length of a string (in characters).
 //'
 //' @param str input character vector
 //' @return characters in each element of the vector
 // [[Rcpp::export]]
 NumericVector strLength(CharacterVector str)
-\end{code}
+\end{verbatim}
 
 Results in the following code in the generated \proglang{R} source file:
 
-\begin{code}
+\begin{verbatim}
 #' The length of a string (in characters).
 #'
 #' @param str input character vector
 #' @return characters in each element of the vector
 strLength <- function(str)
-\end{code}
+\end{verbatim}
 
 \subsection{Packages and sourceCpp}
 



More information about the Rcpp-commits mailing list