0
votes

After multiple test and try I got a pdf from my script using knitr. Almost everything its right but I have some problems with default output: Date and sessionInfo. Also kableExtra library got me error.

I am not using R-studio...

Example of my script:

library(xtable)
library(knitr)
library(kableExtra)

#My first pdf with knitr
data(mtcars)

tabla=mtcars%>%
count(am) 

kable(tabla, caption="tabla uno")

My commands to compile my script and get a pdf:

library(knitr)
setwd("C:/Users/Desktop")
knitr::stitch("C:/Users/Desktop/script.R")

In my pdf result below, you can see that pdf document begin with the date and finish with sessionInfo. I would like edit the date and put my own header and text and would like delete sessionInfo too. Also you can see that kable table is at the end of document and not in the correct order. Also I did try to add echo=FALSE, to avoid show command to make table but without success...:

pdf1 pdf2

1

1 Answers

0
votes

I would suggest you create your document with a YAML header to set variables like author, date, and title. Then you can combine regular text with code chunks as below.

---
title: "Untitled"
author: "Rodrigo"
date: "9/9/2019"
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(dplyr)
library(xtable)
library(knitr)
library(kableExtra)

```

# My first pdf with knitr

Some random text followed by a code block.
```{r}
# A comment
data(mtcars)

tabla=mtcars%>%
count(am) 
```

Here's the table. The code that printed the table has been supressed with `echo = FALSE`.

```{r echo = FALSE}
kable(tabla, caption="tabla uno") %>%
  kable_styling(latex_options = "hold_position")
```

More text

The output looks like this: enter image description here