4

I just discovered the awesome Xaringan package, and I'd like my presentation to be as incremental as possible.

For instance, my introduction slide looks like this:

```{r intro1, echo=TRUE}
version$version.string #should give 3.6.1
```

--

```{r intro2, echo=TRUE}
class(iris)
```

--

```{r intro3, echo=TRUE}
dim(iris) #row, cols
```

--

```{r intro4, echo=TRUE}
colnames(iris)
```

Though, I find it tedious and not much readable to write it that way.

I tried this but it doesn't work:

```{r , echo=TRUE}
version$version.string
class(iris)

-- 

dim(iris)
colnames(iris)
```

Of course, this consider -- as code.

Is there a way to increment my slide from inside the code?

Waylan
  • 37,164
  • 12
  • 83
  • 109
Dan Chaltiel
  • 7,811
  • 5
  • 47
  • 92
  • 1
    This post may give you an inspiration: https://emitanaka.rbind.io/post/knitr-knitr-code/ I know Emi will come to your post later. See if you can figure it out before she arrives :) – Yihui Xie Jul 12 '19 at 16:19
  • Thanks @YihuiXie, this is very interesting! I'm not sure I could get what I want with this way though, maybe I'm not understanding it all... – Dan Chaltiel Jul 13 '19 at 19:12
  • @YihuiXie Actually, this is not exactly relevent in my case. Emi's code is about showing the result of a constructed object, incremented by each line. Mine is about showing the result of each line incrementally. I'm afraid adapting her code won't make mine more readable. – Dan Chaltiel Jul 14 '19 at 14:34
  • 1
    Worst case is `knitr::asis_output('\n--\n')`. I guess there should be more elegant approaches, but I don't have time for this task... – Yihui Xie Jul 14 '19 at 23:01

1 Answers1

3

Yihui pretty much gave the answers in the comments but I elaborate here with one additional tweak which will ensure that the separator code (i.e. knitr::asis_output('\n--\n')) is not visible in the output (this is done by specifying the line number in which the separator appears in the chunk argument as below).

You can the separator code where you want to separate and just make sure the corresponding line number is not echo-ed.

---
output: 
  xaringan::moon_reader: 
    seal: false
---

```{r, echo = -4}
version$version.string 
class(iris)

knitr::asis_output('\n--\n')

dim(iris) 
colnames(iris)
```
Emi
  • 3,514
  • 8
  • 11