проблема с составлением моей колоды флипбука Xaringan - PullRequest
0 голосов
/ 08 мая 2020

У меня проблемы с составлением колоды {flipbookr}. Я могу запустить шаблон без проблем, но получаю пустой файл, который не продвигается, когда я вяжу свой собственный.

enter image description here

Если я удалю вызов chunk_reveal(), он заработает.

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

Насколько я могу судить, единственное, что я делаю не так, как шаблон (кроме сокращения ), состоит в том, чтобы получить внешние данные в блоке настройки, а затем работать с этими данными в блоке, все еще называемом cars. Мне не ясно, является ли что-то подобное проблеме кодирования, которую пользователь SO может помочь мне решить, или проблемой пакета, которую должен увидеть разработчик.

Вот пример, основанный на шаблоне, который должен воспроизводить проблему.

---
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%}
```

1 Ответ

0 голосов
/ 11 мая 2020

Разработчик пакета предложил Я пытаюсь добавить tibble() %>% после covid %>% в блоке "cars", потому что набор данных covid велик. Он по-прежнему не работал с:

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

, но работал с

covid %>% tibble() %>%
...
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...