carbon.js is the easiest way to create beautiful images of your source code.”

This package uses an R6 api to interact with carbon.js and create directly from the console carbon images.

Like the image below:


Initialize new carbon object


The default code in the carbon object is taken from the clipboard.

But can also be defined inline. Code can be a character object of any length.

The code is kept in the object and can be changed at any time.

The main job of the R6 object is to convert all the options into a uri that is sent to the carbon url page, where it is processed.

#> [1] ""

Click the link to see the URI works.

Manipulate carbon object

Aesthetics of the carbon object that can be manipulated

Carbon Variable Carbonate Variable Description Default
l language language r
bg palette layout pallete (vector with c(r,g,b,a) c(r=171,g=184,b=195,a=1)
t template layout template (listed in get_templates()) ‘seti’
wc add_window_control add/remove window controls (circles on top left corner) TRUE
wt window_control_theme change window control themes (listed in get_windows_control_themes()) ‘none’
ds add_drop_shadow add/remove dropshadow TRUE
dsyoff drop_shadow_offset_y shadow vertical offset (px) 20
dsblur drop_shadow_blur_radius shadow blur radius (px) 68
wa auto_adjust_width auto-audjust output width TRUE
pv padding_vertical vertical padding (px) 48
ph padding_horizontal horizontal padding (px) 32
ln add_line_number add/remove line numbers FALSE
fm font_family layout font family (listed in get_font_families()) ‘Hack’
fs font_size font size (px) 14
lh line_height_percent relative space between lines (percent) 133
si square_image output image is square FALSE
es relative_export_size image size in export relative to what is in the preview (1,2 or 4) 1
wm add_watermark add official carbon.js watermark FALSE

Personal Configuration

Users can use a file called carbon.yml and place it in their home directory (~) to override the packages defaults in order to create a session peristent carbon template they like. The config file controls all the public carbon object fields. The following is an example of such a configuration file.

These fields will set

  • The palette (rgba) g and a fields to 175 and 0.7 respectively
  • The template will be set to panda-syntax
  • The font to Fira Code
  • The padding around the output will be made tighter than the system defaults 11px and 14px.

Open carbon code in browser

Set the download directory

x$download_path <- file.path('README_files/download')

Carbonate code directly to file

This function depends on RSelenium

x$carbonate(file = 'myfile.png')

x$template <-'cobalt'
x$carbonate(file = 'new_template.png')

Carbonate code directly to file in specific directory

Closing Browsers

Closing all instances of open browsers used by RSelenium.


Tinyurl You can also put a tinyurl link as a watermark on the image produced that will open to the page that has the code in the image. ``` r x$add_tinyurl If you just want the tinyurl link without the image to use in a tweet you can create it using ``` r x$tiny() #> [1] "" ``` Or you can put the link directly on your clipboard ``` r x$tiny(clip = TRUE) clipr::read_clip() ```
Twitter ##### Direct You can also directly tweet the image. An automatic status is created with two options - Default - Created in R using the Carbonate 📦 - When `add_tinyurl - Manual - Using `tweet_status` you can write your own status. ``` r x

Post image processing

All carbon outputs are collected and saved in the list x$carbons

Combining ``` r x$carbons%>% magick::image_scale('300')%>% magick::image_append() ``` ![](man/figures/unnamed-chunk-28-1.png) ``` r x$carbons%>% magick::image_scale('300')%>% magick::image_append(stack = TRUE) ``` ![](man/figures/unnamed-chunk-28-2.png)
GIFs ``` r x$carbons%>% magick::image_animate(fps = 1) ``` ![](man/figures/unnamed-chunk-29-1.gif)