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

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") 


Is this possible?
Thank you

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

Yes, you should make really good use of knitr code chunks for your purposes! There are many:

Also take a look at this blog post:

Good luck!

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.