For interactive use. enscript()
obtains R's
deparsed internal representation of the input data object and prepares that
object to be input from a script. The function's purpose is to save the user
the inconvenience of reformatting console output data as input code.
Arguments
- .
The data object or expression to transform into script
- to_clipboard
default TRUE; whether to copy the resulting script to the clipboard
Value
The formatted deparsed expression, invisibly if to_clipboard = FALSE. The primary output is the object's internal expression written to clipboard memory
Details
Copying formatted output to the clipboard requires package clipr.
To set up the key-chord ctrl+alt+shift+n
in RStudio, use set_xlr_key_chords()
.
The enscript
key-chord is helpful when making tests for a function's test file.
If using Linux, make sure to install a clipboard tool, e.g. apt-get install xclip or apt-get install xsel
Examples
if (FALSE) {
enscript(letters)
# `letters` is copied to clipboard; press `ctrl + v` to paste the output
enscript(1:5 * 10)
rep("🎊🌈",3) |> enscript()
dplyr::starwars |> head() |> enscript()
(flowers = tail(iris,10))
enscript(flowers)
(days_to_go <- seq.Date(Sys.Date(), by = 1, length.out = 7))
days_to_go |> enscript()
letters |> purrr::set_names(LETTERS) |> enlist() |> enscript()
colours() |> enscript()
candy <- list('lollipops','gum')
enlist(candy, !!candy, !!!candy, enlist(!!!candy)) |> enscript()
enlist(!!letters)
}
# returns the deparsed script as plain text
enscript(letters, to_clipboard = FALSE)
#> [1] "letters <- c(\n\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\", \"k\", \"l\", \n\"m\", \"n\", \"o\", \"p\", \"q\", \"r\", \"s\", \"t\", \"u\", \"v\", \"w\", \"x\", \n\"y\", \"z\"\n)\n"