-
Notifications
You must be signed in to change notification settings - Fork 5
/
README.Rmd
289 lines (205 loc) · 7.1 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
---
output: github_document
always_allow_html: yes
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE,message=FALSE,warning=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/"
)
library(magick)
```
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/carbonate)](https://cran.r-project.org/package=carbonate)
[![](https://cranlogs.r-pkg.org/badges/carbonate)](https://cran.r-project.org/package=carbonate)
[![Travis-CI Build Status](https://travis-ci.org/yonicd/carbonate.svg?branch=master)](https://travis-ci.org/yonicd/carbonate)
[![Coverage Status](https://img.shields.io/codecov/c/github/yonicd/carbonate/master.svg)](https://codecov.io/github/yonicd/carbonate?branch=master)
[![Covrpage Summary](https://img.shields.io/badge/covrpage-Last_Build_2022_08_21-yellowgreen.svg)](https://goo.gl/gNRcCb)
"[carbon.js](https://carbon.now.sh/about) 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:
```{r,include=FALSE}
library(carbonate)
x <- carbon$new(readLines('DESCRIPTION'))
x$carbonate(file = 'myfile.png',path = 'man/figures')
```
```{r, echo=FALSE}
x$carbons
```
## Installation
```{r,eval= FALSE}
#remotes::install_github('yonicd/carbonate')
install.packages('carbonate')
```
## Usage
### Initialize new carbon object
```{r,eval = FALSE}
library(carbonate)
```
The default code in the carbon object is taken from the clipboard.
```{r,eval = FALSE}
x <- carbon$new()
```
But can also be defined inline. Code can be a character object of any length.
```{r, eval = FALSE}
x <- carbon$new(readLines('DESCRIPTION'))
```
The code is kept in the object and can be changed at any time.
```{r}
x$code
```
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.
```{r}
x$uri()
```
Click the [link](`r x$uri()`) 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|
```{r}
x$get_templates()
```
```{r}
x$get_font_families()
```
```{r}
x$get_windows_control_themes()
```
### 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](#manipulate-carbon-object). 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.
```yml
palette:
- g: 175.0
- a: 0.7
template: panda-syntax
font_family: Fira Code
padding_vertical: 11
padding_horizontal: 14
```
### Open carbon code in browser
```{r,eval=FALSE}
x$browse()
```
### Set the download directory
```{r,eval = FALSE}
x$download_path <- file.path('README_files/download')
```
### Carbonate code directly to file
This function depends on RSelenium
```{r,eval = FALSE}
x$carbonate(file = 'myfile.png')
```
```{r, echo=FALSE}
x$carbons
```
```{r,echo=FALSE}
Sys.sleep(2)
```
```{r}
x$template <-'cobalt'
x$carbonate(file = 'new_template.png')
```
```{r,echo=FALSE}
Sys.sleep(2)
```
```{r}
x$font_family <-'IBM Plex Mono'
x$carbonate(file = 'new_font.png')
```
### Carbonate code directly to file in specific directory
```{r,echo=FALSE}
Sys.sleep(2)
```
### Closing Browsers
Closing all instances of open browsers used by RSelenium.
```r
x$stop_all()
```
### Sharing
<details><summary>Tinyurl</summary>
You can also put a tinyurl link as a watermark on the image produced that will open to the carbon.now.sh page that has the code in the image.
```{r,echo=FALSE}
Sys.sleep(2)
```
```{r}
x$add_tinyurl <- TRUE
x$carbonate(file = 'tiny_url.png')
```
If you just want the tinyurl link without the image to use in a tweet you can create it using
```{r}
x$tiny()
```
Or you can put the link directly on your clipboard
```{r, eval = interactive()}
x$tiny(clip = TRUE)
clipr::read_clip()
```
</details>
<details><summary>Twitter</summary>
##### Direct
You can also directly tweet the image. An automatic status is created with two options
- Default
- `r 'Created in R using the Carbonate \U0001f4e6'`
- When `add_tinyurl <- TRUE`
- `r sprintf('%s\nCheck out this script at \U0001f517 %s', 'Created in R using the Carbonate \U0001f4e6', x$tiny())`
- Manual
- Using `tweet_status` you can write your own status.
```{r,eval=FALSE}
x <- carbonate::carbon$new()
x$tweet <- TRUE
x$carbonate()
```
##### Post process (Batch)
If you have images stored in `x$carbons` you can post them also in a tweet using.
```{r,eval = FALSE}
# for multiple png attachments
x$rtweet(x$carbons,media_type = 'png') #using default status
# subsets of images
x$rtweet(status='These are images',x$carbons[c(1,3)],media_type = 'png')
# for gifs
x$rtweet(status='This is a gif', x$carbons,media_type = 'gif')
```
</details>
### Post image processing
All carbon outputs are collected and saved in the list `x$carbons`
<details><summary>Combining</summary>
```{r}
x$carbons%>%
magick::image_scale('300')%>%
magick::image_append()
x$carbons%>%
magick::image_scale('300')%>%
magick::image_append(stack = TRUE)
```
</details>
<details><summary>GIFs</summary>
```{r}
x$carbons%>%
magick::image_animate(fps = 1)
```
</details>