Title: | Pretty Print R Code in the Terminal |
---|---|
Description: | Replace the standard print method for functions with one that performs syntax highlighting, using ANSI colors, if the terminal supports them. |
Authors: | Gábor Csárdi [aut, cre], Posit Software, PBC [cph, fnd] |
Maintainer: | Gábor Csárdi <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.1.0.9000 |
Built: | 2024-11-04 05:49:40 UTC |
Source: | https://github.com/r-lib/prettycode |
prettycode
syntax highlighting styleA style function must return a named list of functions. Possible entries:
reserved
: reserved words
number
: numeric literals
null
: the NULL
constant
operator
: operators, including assignment
call
: function calls
string
: character literals
comment
: comments
bracket
: brackets: (){}[]
default_style()
default_style()
Each entry in a list must be a function that takes a character
scalar, and returns a character scalar with the exception of bracket
which should be a list of these type of functions defining a color sequence.
The default style adds ANSI formatting to the code.
Note that you can also change the code if you like, e.g. to include a unicode arrow character instead of the two-character assignment operator.
highlight(deparse(get), style = default_style())
highlight(deparse(get), style = default_style())
Syntax highlight R code
highlight(code, style = default_style())
highlight(code, style = default_style())
code |
Character vector, each element is one line of code. |
style |
Style functions, see |
Character vector, the highlighted code.
highlight(deparse(ls)) cat(highlight(deparse(ls)), sep = "\n")
highlight(deparse(ls)) cat(highlight(deparse(ls)), sep = "\n")
Replace the standard print method for functions with one that performs syntax highlighting, using ANSI colors, if the terminal supports them.
prettycode(warn_conflicts = TRUE)
prettycode(warn_conflicts = TRUE)
warn_conflicts |
logical. If |
To turn on pretty printing of functions, you need to call
prettycode::prettycode()
. It might be a good idea to call it
from your .Rprofile
.
## S3 method for class ''function'' print(x, useSource = TRUE, style = default_style(), ...)
## S3 method for class ''function'' print(x, useSource = TRUE, style = default_style(), ...)
x |
Function to print. |
useSource |
Whether to use the stored source code, if available. |
style |
The highlight style to use, see |
... |
Not used currently, for compatibility with the |
The function, invisibly.