Re: Bookdown; Trying to Run R-code Inside Manuscript AND Display It

bookdown

#1

I am using Bookdown for my grad project.

I would like to have a section of my manuscript run R-code then print the results IN the booklet. I am trying to teach specific tasks and would like to carry out the steps in the booklet.

The code is displayed. And the code runs separately BUT does NOT display in book.

I am emulating Roger Peng's book, Exploratory Data Analysis book where he does much the same thing.

For example:

So far I am using:

Load data:

#{r loadData}

pima.women <- read.csv("~/resources/Pima.tr2.csv") 

dim(pima.women)

Is this possible?
Thank you
Matt


#2

OK, I think I got it. This time reading documentation for Bookdown more carefully this time. ;)))

For Example:

# ```{r chunk-label, echo = TRUE, fig.cap = 'A figure caption.'}  ADDED Like this...
1 + 1
rnorm(10)  # 10 random numbers
plot(dist ~ speed, cars)  # a scatterplot

#3

Yes, you should make really good use of knitr code chunks for your purposes! There are many: https://yihui.name/knitr/options/

Also take a look at this blog post:

Good luck!
Alison