Day 4: carbonate

Welcome back for the 4th day of the #packagecalendar, today we will revisit Jonathan Sidi’s creations by looking at carbonate. The package is a nice way of interacting with carbon.js.

the package is available from CRAN and can be downloaded with

install.packages("carbonate")

The carbonate package uses the R6 classes which is why the syntax might look a little different then what you are used to.

library(carbonate)

The default behavior is to take the code you have in your clipboard. Here we create an object x with the code used to display yesterday’s secret.

x <- carbon$new()

We can take a look at the code with

x$code
##  [1] "library(tidyverse)"                                                       
##  [2] "symbols <- c('.', '~', \"'\", 'O', \"'\", '~', '.')"                      
##  [3] "layer_size <- seq(3, 45, by = 4)"                                         
##  [4] ""                                                                         
##  [5] "things <- rep(symbols, length.out = sum(layer_size))"                     
##  [6] ""                                                                         
##  [7] "rows <- split(things, rep(seq_along(layer_size), times = layer_size)) %>%"
##  [8] "  sapply(paste0, collapse = \"\")"                                        
##  [9] ""                                                                         
## [10] "details(summary = \"Open for a special presents\","                       
## [11] "        tibble(x = 0, "                                                   
## [12] "               y = -as.numeric(names(rows)),"                             
## [13] "               labels = rows) %>%"                                        
## [14] "          ggplot(aes(x, y, label = labels)) +"                            
## [15] "          geom_text(size = 10) +"                                         
## [16] "          theme_void()"                                                   
## [17] ")"

If you want the carbon output you have two ways to go

Browse

calling the browse() method takes you to carbon.now.sh with your code and configurations already there. From there you can play more with the configurations or simply press export to download your image.

x$browse()

RSelenium

If you have RSelenium installed you can create the image without leaving R. You just set the download path and run the carbonate() method.

x$download_path <- file.path("~/Desktop/")
x$carbonate(file = 'myfile.png')

No matter what you choose you will end up with something like this:

There is a ton of options to manipulate. So go wild and make it your own! See you next time!