1- I am struggling to find a way to create a table in R Markdown to insert some data manually (data not generated in R)
2- Is it possible to show the R code in a chunk without running when knitting the file in PDF? I just want to show it, in fact, if there is a way to run the code but append in appendix that would even be better. So code is not show at the chunk where it has run instead it’s at the end of the file. I hope this make sense.
Many Thanks for this. My first question was about adding static data to an r Markdown file. Sorry this is what I meant. I.e. if i had a table of A=1, B=2...etc. How to create this in a table form. Thanks for your help.
To your first point, you can output a table in a R Markdown document in several ways. There are many packages that support nice table formatting. The knitr package provides kable. You can add a table like this:
To your second question, you don't need a chunk name, you can just use the default chunk names. However, naming chunks is good practice as it makes it easier to navigate the document, and you can filter chunk labels to only include certain chunks in the code appendix. Having a naming system makes this much easier.
My recommendation would be to create an H-level markdown header with a label, and then refer to that label for automatic cross-referencing, try this:
---
title: "My awesome report"
author: "Me"
output:
bookdown::pdf_document2:
toc: false
number_sections: false
linkcolor: blue
---
# Section
Here is a cool histogram, you can find the code for it [here](#appendix).
The code for this section is found in the [Code Appendix].
```{r chunk1, echo=FALSE}
# Here is some sweet code
hist(rnorm(100))
```
# Code Appendix {#appendix}
```{r ref.label="chunk1", echo=TRUE, eval=FALSE}
```
We labeled the Code Appendix section with a label of #appendix. We can use that to cross-reference that section in our text. You can do that with normal markdown-style linking like: [text shown](#label). You may also just put the full and exact section name in square brackets like: [Code Appendix]. All work.