Skip to content

Commit

Permalink
nest_paragraphs carry over other columns
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt committed Apr 7, 2018
1 parent ad5bcac commit 0766d5a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,7 +1,7 @@
Package: ggpage
Type: Package
Title: Creates Page Layout Visualizations in R
Version: 0.2.0
Version: 0.2.1
Authors@R: person("Emil", "Hvitfeldt", email = "emilhhvitfeldt@gmail.com", role = c("aut", "cre"))
Description: This package facilitates the creation of page layout
visualizations in which words are represented as rectangles with sizes
Expand Down
20 changes: 16 additions & 4 deletions R/nest_paragraphs.R
Expand Up @@ -11,9 +11,21 @@
nest_paragraphs <- function(data, input, ...) {
quo_input <- rlang::quo_name(rlang::enquo(input))

data[[quo_input]] %>%
sections <- data[[quo_input]] %>%
stringr::str_wrap(...) %>%
stringr::str_split("\n") %>%
unlist() %>%
data.frame(text = ., stringsAsFactors = FALSE)
stringr::str_split("\n")

purrr::map_df(seq_len(nrow(data)),
~ data.frame(text = sections[[.x]], stringsAsFactors = FALSE) %>%
bind_cols(
bind_rows(
replicate(
length(sections[[.x]]),
dplyr::select(data, -quo_input)[.x, ],
simplify = FALSE)
)
)
)
}


3 changes: 2 additions & 1 deletion vignettes/different-features.Rmd
Expand Up @@ -116,7 +116,7 @@ ggpage_build(tinderbox, align = "both") %>%
Lastly for convience does `ggpage` include a way to transform a data.frame with paragraph tokens to a data.frame with line tokens.

```{r}
nest_paragraphs(tinderbox_paragraph, text) %>%
nest_paragraphs(data = tinderbox_paragraph, input = text) %>%
head()
nest_paragraphs(tinderbox_paragraph, text, width = 40) %>%
Expand All @@ -126,3 +126,4 @@ nest_paragraphs(tinderbox_paragraph, text, width = 40) %>%




0 comments on commit 0766d5a

Please sign in to comment.