Text cleaning in flipbookr

43 Views Asked by At

I used the minimal flipbookr template and like to illustrate some text cleaning steps line by line with code next to it. This is my code chunk:

library(tidyverse)
library(tidytext)
library(stringr)
library(wikifacts)

R_EN <- wiki_define('R (programming language)')
R_EN #BREAK

R_EN %>% 
    ## Remove digits
    str_remove_all("[:digit:]") %>% #BREAK
    ## Remove punctuation
    str_remove_all("[[:punct:]]") %>% #BREAK
    ## Make everything lowercase
    str_to_lower() %>% #BREAK
    ## Remove any trailing whitespace around the text
    str_trim("both") %>% #BREAK
    ## Remove newline character
    str_replace_all("[\r\n]" , " ") #BREAK

Only the first few words are shown on the right (compiled markdown). How can I make all (or at least more) lines of a long character appear?

enter image description here

Like they do in the console:

enter image description here

1

There are 1 best solutions below

0
Manoj Kumar On

how about this code:

---
title: "A flipbook"
subtitle: "With flipbookr and xaringan"
author: "Manoj Kumar"
output:
  xaringan::moon_reader:
    lib_dir: libs
    css: [default, hygge, ninjutsu]
    nature:
      ratio: 16:9
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
---


```{r, 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 scratch can be time consuming
knitr::opts_chunk$set(fig.width = 6, message = FALSE, warning = FALSE, comment = "", cache = F)

# devtools::install_github("EvaMaeRey/flipbookr")
# install.packages("xaringan", dependencies = T)

library(flipbookr)
library(tidyverse)
library(tidytext)
library(stringr)
library(wikifacts)

R_EN <- wiki_define('R (programming language)')
```


`r chunk_reveal("my_wiki")`


```{r my_wiki, include = FALSE, warning=FALSE}

R_EN #BREAK
```


`r chunk_reveal("my_wiki1")`

```{r my_wiki1, include = FALSE, warning=FALSE}
R_EN %>% 
    ## Remove digits
    str_remove_all("[:digit:]") %>% #BREAK
    ## Remove punctuation
    str_remove_all("[[:punct:]]") %>% #BREAK
    ## Make everything lowercase
    str_to_lower() %>% #BREAK
    ## Remove any trailing whitespace around the text
    str_trim("both") %>% #BREAK
    ## Remove newline character
    str_replace_all("[\r\n]" , " ") #BREAK
```




<!-- adjust font size in this css code chunk, currently 80 -->

```{css, eval = TRUE, echo = FALSE}
.remark-code{
    line-height: 1.5; 
    font-size: 80%; 
    white-space: pre-wrap;
    /* width: 400px; */ /* Adjust the width as needed */
    width: 80%; /* Adjust the percentage as needed */
    overflow-x: auto;
    }

@media screen and (max-width: 600px) {
    .remark-code {
        width: 100%; /* Adjust for smaller screens */
        white-space: pre-wrap;
    }
}

@media print {
  .has-continuation {
    display: block;
    overflow-x: auto !important;
  }
}

code.r.hljs.remark-code{
  position: relative;
  overflow-x: hidden;
}


code.r.hljs.remark-code:hover{
  overflow-x:visible;
  width: 500px;
  border-style: solid;
}
```

This gives the text wrapped as shown in the below snapshot:

enter image description here

And

enter image description here

Please let me know if this helps you...