Package 'carbonate'

Title: Interact with 'carbon.js'
Description: Create beautiful images of source code using 'carbon.js'<https://carbon.now.sh/about>.
Authors: Jonathan Sidi [aut, cre]
Maintainer: Jonathan Sidi <[email protected]>
License: MIT + file LICENSE
Version: 0.1.4
Built: 2024-09-21 03:53:33 UTC
Source: https://github.com/yonicd/carbonate

Help Index


open $uri to in browser window

Description

opens the uri address in $uri in the browser window.

Usage

.browse(self, private)

Arguments

self

carbon self object

private

carbon private object

See Also

carbon

Examples

x <- carbon$new('x <- 1')
if(interactive())
 x$browse()

Carbonate script lines to a carbon image

Description

Main function of the package that invokes RSelenium to open a browser to the carbon.js uri, create an image and download the file.

Usage

.carbonate(self, private, file, path, code, rD, driver)

Arguments

self

carbon self object

private

carbon private object

file

character, name of file to save image as

path

character, path to save the image

code

character, lines of script to make carbon image from

rD

RSelenium driver

driver

character, select either 'firefox' or 'chrome' driver

Details

Script is passed to https://carbon.now.sh/ is downloaded to the tempdir() and appended to the list $carbons using RSelenium and Chrome.

Value

image object

See Also

carbon, rsDriver

Examples

if(interactive()){
 x <- carbon$new('x <- 1')
 x$carbonate()
 }

chrome webdriver functions

Description

Functions to open,close,set chrome webdriver

Usage

.chromeOptions(self, private)

Arguments

self

carbon self object

private

carbon private object

See Also

carbon, chrome


encode uri for carbon.js

Description

encode uri string for carbon.js. Augmented version of than URLencode

Usage

.encode(self, private, URL, reserved, repeated)

Arguments

self

carbon self object

private

carbon private object

URL

character, uri string to url encode

reserved

boolean, should ‘reserved’ characters be encoded?

repeated

boolean, should apparently already-encoded URLs be encoded again?

Value

character

See Also

URLencode, carbon


gecko webdriver functions

Description

Functions to open,close,set gecko webdriver

Usage

.firefoxOptions(self, private)

Arguments

self

carbon self object

private

carbon private object

See Also

carbon, gecko


carbon get functions

Description

function that gets the available list of aesthetic values of fields

Usage

.get_windows_control_themes(self, private)

.get_font_families(self, private)

.get_templates(self, private)

Arguments

self

carbon self object

private

carbon private object

See Also

carbon


concatenate the carbon options to a string

Description

combine all the carbon options into a carbon.js valid string

Usage

.options(self, private, code)

Arguments

self

carbon self object

private

carbon private object

code

character, script to embbed into the uri

Value

OUTPUT_DESCRIPTION

See Also

carbon


send tweets using carbonate outputs

Description

wrapper for post_tweet to send tweets with media created using carbonate.

Usage

.rtweet(self, private, media, status = self$tweet_status,
  media_format = c("png", "gif"), ...)

Arguments

self

carbon self object

private

carbon private object

media

magick-image object or path to image

status

character, status to attach to post, Default: self$tweet_status

media_format

character, type of media to tweet, Default: c('png','gif')

...

arguments to pass to post_tweet

Details

If multiple images are passed they can be either converted to a gif by setting media_format to 'gif' or attached each one to the post.

Value

outcome from rtweet

See Also

image_write post_tweet

Examples

## Not run: 
x <- carbonate::carbon$new()
x$carbonate(code = readLines(system.file('DESCRIPTION',package='carbonate')))
x$carbonate(code = 'x+2')

# using default status value (x$tweet_status)
x$rtweet(system.file('figures/hex_black_small.png',package='carbonate'))

x$rtweet(status = 'these are two pngs',media = x$carbons,media_format='png')
x$rtweet(status = 'this is a gif', media = x$carbons,media_format='gif')


## End(Not run)

carbon set functions

Description

function that set the aesthetics of the carbon image output

Usage

.set_template(self, private, template)

.set_window_control_theme(self, private, theme)

.set_font_family(self, private, family)

Arguments

self

carbon self object

private

carbon private object

template

character, name of template to set $template to

theme

character, theme to set $theme to

family

character, font family to set $font_family to

See Also

carbon


RSelenium webdriver functions

Description

Functions to open,stop, stop_all RSelenium sessions

Usage

.start(self, private, eCap, driver = c("firefox", "chrome"))

.driver_start(self, private, driver = c("chrome", "firefox"))

.driver_stop(self, private)

.stop(self, private)

.stop_all(self, private)

.set_port(self, private, port = NULL)

.get_port(self, private)

Arguments

self

carbon self object

private

carbon private object

eCap

chromeOptions passed into rsDriver

driver

character, select either 'firefox' or 'chrome' driver

port

integer, port for the rsDriver to use, if NULL then a random port is selected

See Also

carbon


convert carbon uri to tinyurl

Description

convert carbon uri to tinyurl with option to attach to clipboard.

Usage

.tiny(self, private, clip = FALSE)

Arguments

self

carbon self object

private

carbon private object

clip

boolean, write tinyurl to clipboard, Default: FALSE

Details

If clip is set to TRUE write_clip will put the tinyurl on the clipboard.

Value

character


URI constructor

Description

Function that is called in a carbon object to construct valid uri to send to browser

Usage

.uri(self, private, code)

Arguments

self

carbon self object

private

carbon private object

code

character, script to embbed into the uri

See Also

carbon

Examples

if(interactive()){

x <- carbon$new('x <- 1')

# populate from self$code
x$uri()

# enter manually
x$uri(code = 'x <- y + 3')

}

Carbon R6 class

Description

The Carbon generator creates a new Carbon-object, which is the class containing all the app logic. The class is based on the R6 OO-system and is thus reference-based with methods and data attached to each object, in contrast to the more well known S3 and S4 systems.

Initialization

A new 'Carbon'-object is initialized using the new() method on the generator:

x <- carbon$new(code = clipr::read_clip())

Fields


Public Fields

Description of fields of the R6 object that can be set by the user can be found in the following page.

Methods


Interacting with Browser
$carbonate Using RSelenium fetch the carbon image output
$browse open $uri in the browser

Aesthetics
$set_template set $template
$get_templates get a list of possible templates
$set_window_control_theme set $windows_control_theme
$get_windows_control_themes get a list of possible window control themes
$set_font_family set $font_family
$get_font_families get a list of possible fonts

URI Building
$uri construct valid carbon.js uri
$options return all current carbon options
$encode URL encode a string for the $uri
$tiny Create tinyurl from $uri
$rtweet Send tweets containing media generated from carbon

Webdriver Settings
$chromeOptions construct a chromeOptions object
$chrome_start start a chrome session
$chrome_stop stop a chrome session
$start start a RSelenium session
$stop stop a RSelenium session
$stop_all stop all active RSelenium sessions
$get_port Get active port
$set_port Set new port

Carbon object fields

Description

Fields that can be changed in the Carbon object

Arguments

code

character, script to embbed, Default: NULL

palette

numeric, layout pallete, Default: c(r=171,g=184,b=195,a=1)

template

character, layout template, Default: 'seti'

add_window_control

boolean, add/remove window controls (circles on top left corner), Default: TRUE

window_control_theme

character, change window control themes, Default: 'none'

language

character, language, Default: 'r'

add_drop_shadow

boolean, add/remove dropshadow, Default: TRUE

drop_shadow_offset_y

numeric, shadow vertical offset (px), Default: 20

drop_shadow_blur_radius

numeric, shadow blur radius (px), Default: 68

auto_adjust_width

boolean, auto-audjust output width, Default: TRUE

padding_vertical

numeric, vertical padding (px), Default: 48

padding_horizontal

numeric, horizontal padding (px), Default: 32

add_line_number

boolean, add/remove line numbers, Default: FALSE

font_family

character, layout font family, Default: 'Hack'

font_size

numeric, font size (px), Default: 14

line_height_percent

numeric, relative space between lines (percent), Default: 133

square_image

boolean, output image is square, Default: FALSE

relative_export_size

numeric, image size in export relative to what is in the preview (1,2 or 4), Default: 1

add_watermark

boolean, add official carbon.js watermark, Default: FALSE

add_tinyurl

boolean, add tinyurl link to image directing to the carbon page that created the image, Default: FALSE

tinyurl_location

character, string with gravity value to place the annotate tinyurl address on image, Default: 'southeast'

tweet

boolean, tweet out the image using post_tweet

tweet_status

character, status to add to the tweet. If add_tinyurl is TRUE then a link to the url will be appended to the status automatically, Default: 'Created in R using the Carbonate (Package Icon)'

add_timestamp

boolean, add timestamp to output filename, Default: FALSE

carbons

list, storage of rendered carbon images, Default: NULL

download_path

character, path to download the images, Default: tempdir()

chrome_args

character, arguments passed to chrome browser, Default: c('–disable-gpu', '–window-size=1280,800')

chrome_pref

list, preferences passed to chrome browser, Default: list("profile.default_content_settings.popups" = 0L,"download.prompt_for_download" = FALSE,"download.default_directory" = tempdir())

rD

RSelenium Driver object

cDrv

Chrome Driver object from wdman

See Also

carbon


convert uri to tinyurl

Description

convert uri to tinyurl.

Usage

tinyurl(uri)

Arguments

uri

character, the uri to convert

Value

character