@@ -55,7 +55,9 @@ watermark: false
5555footer_contents : " Rcpp Vignette"
5656
5757# Produce a pinp document
58- output : pinp::pinp
58+ output :
59+ pinp::pinp :
60+ collapse : true
5961
6062# Local additiona of a few definitions we use
6163header-includes : >
@@ -86,6 +88,7 @@ vignette: >
8688``` {r setup, include=FALSE}
8789knitr::opts_chunk$set(cache=TRUE)
8890library(Rcpp)
91+ options("width"=50, digits=5)
8992```
9093
9194
193196As a first step, and chiefly to establish that the toolchain is set up correctly, consider
194197a minimal use case such as the following:
195198
196- ``` {r evalCpp, eval=FALSE }
199+ ``` {r evalCpp}
197200library("Rcpp")
198201evalCpp("2 + 2")
199202```
@@ -225,6 +228,7 @@ isOddR <- function(num = 10L) {
225228 result <- (num %% 2L == 1L)
226229 return(result)
227230}
231+ isOddR(42L)
228232```
229233
230234The operator ` %% ` implements the $\bmod$ operation in \rlangns. For the default
@@ -259,7 +263,7 @@ that represents the \cpp code. Upon calling the `cppFunction()`, and similarly t
259263earlier example involving ` evalCpp() ` , the \cpp code is both _ compiled_ and _ linked_ , and
260264then _ imported_ into \rlang under the name of the function supplied (_ e.g._ here ` isOddCpp() ` ).
261265
262- ``` {r isOddRcpp, cache=TRUE, eval=FALSE }
266+ ``` {r isOddRcpp}
263267library("Rcpp")
264268cppFunction("
265269bool isOddCpp(int num = 10) {
@@ -509,7 +513,7 @@ set.seed(123)
509513rnorm(3)
510514```
511515
512- # Translating Code from \rlang into \rcppns: A Bootstrapping Example
516+ # Translating Code from \rlang into \rcppns: Bootstrap Example
513517
514518Statistical inference relied primarily upon asymptotic theory until
515519\cite{Efron:1979: Bootstrap } proposed the bootstrap. Bootstrapping is known
@@ -564,7 +568,7 @@ make_boot_graph <- function(ds, actual, type, ylim){
564568 abline(v = actual, col = "orange2", lwd = 2)
565569 lines(density(ds))
566570}
567- pdf("bootstrap.pdf", width=6.5, height=3.25)
571+ pdf("figures/ bootstrap.pdf", width=6.5, height=3.25)
568572par(mfrow=c(1,2))
569573make_boot_graph(result_r[,1], 21, "Mean", c(0, 1.23))
570574make_boot_graph(result_r[,2], 10, "SD", c(0, 1.85))
@@ -573,7 +577,7 @@ dev.off()
573577
574578\begin{figure* }
575579 \begin{center}
576- \includegraphics[ width=6.5in, height=3.25in] {bootstrap}
580+ \includegraphics[ width=6.5in, height=3.25in] {figures/ bootstrap}
577581 \caption{Results of the bootstrapping procedure for sample mean and variance.}
578582 \label{fig: bootstrap-graphs }
579583 \end{center}
@@ -809,13 +813,10 @@ Rcpp::List fastLm(const arma::mat& X,
809813 const arma::colvec& y) {
810814 // Dimension information
811815 int n = X.n_rows, p = X.n_cols;
812-
813816 // Fit model y ~ X
814817 arma::colvec coef = arma::solve(X, y);
815-
816818 // Compute the residuals
817819 arma::colvec res = y - X*coef;
818-
819820 // Estimated variance of the random error
820821 double s2 =
821822 std::inner_product(res.begin(), res.end(),
0 commit comments