Update On ESC/POS Package Work
[This article was first published on R – rud.is, 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.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
The morning before work was super productive and there is a nigh-complete DSL for ESC/POS commands along with the ability to just print {ggplot2}/{grid} object.
I changed the package name to {escpos} since it is no longer just plot object focused, and the DSL looks a bit like this:
library(stringi) library(hrbrthemes) library(ggplot2) library(escpos) ggplot() + geom_point( data = mtcars, aes(wt, mpg), color = "red" ) + labs( title = "A good title" ) + theme_ipsum_es(grid="XY") -> gg epson_ip = "HOSTNAME_OR_IP_OF_YOUR_PRINTER" escpos(epson_ip) |> pos_bold("on") %>% pos_align("center") %>% pos_size("2x") %>% pos_underline("2dot") %>% pos_plaintext("This Is A Title") %>% pos_lf(2) |> pos_underline("off") %>% pos_size("normal") %>% pos_align("left") %>% pos_bold("off") %>% pos_font("b") %>% pos_plaintext( stringi::stri_rand_lipsum(1) ) |> pos_lf(2) |> pos_font("a") %>% pos_plaintext( paste0(capture.output( str(mtcars, width = 40, strict.width = "cut") ), collapse = "\n") ) |> pos_lf(2L) |> pos_plot(gg, color = TRUE) %>% pos_lf(2L) |> pos_font("c") %>% pos_plaintext( stringi::stri_rand_lipsum(1, start_lipsum = FALSE) ) |> pos_lf(3) |> pos_cut() %>% pos_print()
FIN
I still need to make a more generic options “setter” (i.e. so one can set multiple modes in one function call), and I think supporting some kind of markdown/HTML subset to make it easier just to specify that without using the full DSL would be helpful. More updates over the coming weeks!
To leave a comment for the author, please follow the link and comment on their blog: R – rud.is.
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.