0

I am having trouble compiling my {flipbookr} deck. I'm able to run the template without problems, but I'm getting a blank file that will not advance when I knit my own.

enter image description here

If I remove the call to chunk_reveal() it works.

r chunk_reveal("cars", break_type = "auto")

As far as I can tell, the only thing I'm doing differently from the template (aside from shortening it), is to get external data in the setup chunk, and then working with that data in the chunk still named cars.

FYI, I posted an issue on the package github repo, but it's not clear to me whether something like this is a coding problem that a SO user could help me solve or a package issue the developer should see.

Here is an example based on the template that should reproduce the issue.

---
title: "The art of flipbooking"
subtitle: "With flipbookr and xaringan"
author: "Gina Reynolds, December 2019"
output:
  xaringan::moon_reader:
    lib_dir: libs
    css: [default, hygge, ninjutsu]
    nature:
      ratio: 16:10
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
---

```{r setup, include = F}
# This is the recommended set up for flipbooks
# you might think about setting cache to TRUE as you gain practice --- building flipbooks from scracth can be time consuming
knitr::opts_chunk$set(fig.width = 6, message = FALSE, warning = FALSE, comment = "", cache = FALSE, fig.retina = 3)
library(flipbookr)
library(tidyverse)

covid <- read.csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv", 
                  stringsAsFactors = FALSE)
```



# Using `flipbookr::chunk_reveal()`

You will use the `chunk_reveal()` function [inline](https://rmarkdown.rstudio.com/lesson-4.html) to generate the derivitive code chunks, rather than inside of a code chunk, so that the text that is generated is interpreted correctly when rendered.  The inline code will look something like this:

<!-- The above is for the html output version, just look at the examples below if you are in the source! -->
```markdown
``r "r chunk_reveal(chunk_name = \"cars\", break_type = \"user\")"``
``` 

There are several modalities that you might be interested in using for "flipbookifying" your code and the next section is dedicated to demoing some of them below.

- **break type** -- *which lines of code should be revealed when*, `break_type` defaults to "auto"
- **display type** -- *display code and output, or just output, or just code?*, `display_type` defaults to "both"
- **assignment type** -- *does code chunk use left assignment?*, `left_assign` defaults to FALSE

---

At first we'll apply our flipbooking to the below input code - the code chunk is named "cars".  For now I set echo = TRUE for this code chunk, so you can see the code content but sometimes you might like to set echo to FALSE. This code uses tidyverse tools, so we loaded that too in the "setup" code chunk at the beginning of the template. 

```{r cars, include = FALSE}
covid %>%
  filter(state!="District of Columbia" &
           state!="Puerto Rico" &
           state!="Hawaii" &
           state!="Alaska") %>%
  select(date, fips, cases, deaths) %>%
  mutate(date = lubridate::ymd(date)) %>%
  mutate(fips = stringr::str_pad(fips, width=5, pad="0")) %>%
  mutate(month = lubridate::month(date, 
                                  label=TRUE, 
                                  abbr=TRUE),
         day = lubridate::day(date),
         monthDay = paste(month, day, sep=" ")) 
```

---

# `break_type`

Notice the regular comments and the special #BREAK comments, these will be used for a couple of the different "break type" modalities.


```{r, code = knitr::knit_code$get("cars"), eval = FALSE, echo = TRUE}
```

<!-- Also notice how we've created a new code chunk with the code from the previous chunk by calling knitr::knit_code$get("cars"). -->
<!-- This slide is also about giving you some intuition about how flipbooking works in the background. -->
<!-- (more on this [here](https://emitanaka.rbind.io/post/knitr-knitr-code/)) -->

---

## break_type = "auto"

One parameter of flipbooking is the break_type.  The default is "auto", in which appropriate breakpoints are determined automatically --- by finding where parentheses are balanced. 

<!-- display the user input code as a refresher -->
```{r, code = knitr::knit_code$get("cars"), eval = FALSE, echo = TRUE}
```


---

`r chunk_reveal("cars", break_type = "auto")`

---


```{css, eval = TRUE, echo = FALSE}
.remark-code{line-height: 1.5; font-size: 80%}
```
Eric Green
  • 7,385
  • 11
  • 56
  • 102

1 Answers1

0

The package developer suggested I try adding tibble() %>% after covid %>% in the "cars" chunk because the covid dataset is large. It still failed with:

covid %>%
tibble() %>%
...

but worked with

covid %>% tibble() %>%
...
Eric Green
  • 7,385
  • 11
  • 56
  • 102