Site icon R-bloggers

Templated output in R

[This article was first published on R on Abhijit Dasgupta, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Earo Wang, who is the curator for the We are R-Ladies twitter feed this week (last week of April, 2019), had a really nice tweet about using the whisker package to create a template incorporating text and data in R. Her example created a list of tidyverse packages with descriptions.

I really liked the example, but thought that the glue package might be able to do the same thing. I used Earo’s code to generate a tibble with the package names and descriptions, and glue_data to create the templated list.

library(tidyverse)
library(glue)
tidy_pkgs <- 
  tibble('pkgs' = c('ggplot2','purrr','readr','tidyr',
                    'dplyr','forcats','lubridate','stringr')) %>% 
  mutate(descr = map_chr(pkgs, ~packageDescription(., fields='Description')))

glue_data(tidy_pkgs, 
          "- [**{pkgs}**](http://{pkgs}.tidyverse.org): {descr}")

To leave a comment for the author, please follow the link and comment on their blog: R on Abhijit Dasgupta.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.