Description Usage Arguments Value Examples
Syntax highlight R code
1 | highlight(code, style = default_style())
|
code |
Character vector, each element is one line of code. |
style |
Style functions, see |
Character vector, the highlighted code.
1 2 |
Attaching package: 'prettycode'
The following object is masked from 'package:base':
print.function
[1] "function (name, pos = -1L, envir = as.environment(pos), all.names = FALSE, "
[2] " pattern, sorted = TRUE) "
[3] "{"
[4] " if (!missing(name)) {"
[5] " pos <- tryCatch(name, error = function(e) e)"
[6] " if (inherits(pos, \"error\")) {"
[7] " name <- substitute(name)"
[8] " if (!is.character(name)) "
[9] " name <- deparse(name)"
[10] " warning(gettextf(\"%s converted to character string\", "
[11] " sQuote(name)), domain = NA)"
[12] " pos <- name"
[13] " }"
[14] " }"
[15] " all.names <- .Internal(ls(envir, all.names, sorted))"
[16] " if (!missing(pattern)) {"
[17] " if ((ll <- length(grep(\"[\", pattern, fixed = TRUE))) && "
[18] " ll != length(grep(\"]\", pattern, fixed = TRUE))) {"
[19] " if (pattern == \"[\") {"
[20] " pattern <- \"\\\\[\""
[21] " warning(\"replaced regular expression pattern '[' by '\\\\\\\\['\")"
[22] " }"
[23] " else if (length(grep(\"[^\\\\\\\\]\\\\[<-\", pattern))) {"
[24] " pattern <- sub(\"\\\\[<-\", \"\\\\\\\\\\\\[<-\", pattern)"
[25] " warning(\"replaced '[<-' by '\\\\\\\\[<-' in regular expression pattern\")"
[26] " }"
[27] " }"
[28] " grep(pattern, all.names, value = TRUE)"
[29] " }"
[30] " else all.names"
[31] "}"
function (name, pos = -1L, envir = as.environment(pos), all.names = FALSE,
pattern, sorted = TRUE)
{
if (!missing(name)) {
pos <- tryCatch(name, error = function(e) e)
if (inherits(pos, "error")) {
name <- substitute(name)
if (!is.character(name))
name <- deparse(name)
warning(gettextf("%s converted to character string",
sQuote(name)), domain = NA)
pos <- name
}
}
all.names <- .Internal(ls(envir, all.names, sorted))
if (!missing(pattern)) {
if ((ll <- length(grep("[", pattern, fixed = TRUE))) &&
ll != length(grep("]", pattern, fixed = TRUE))) {
if (pattern == "[") {
pattern <- "\\["
warning("replaced regular expression pattern '[' by '\\\\['")
}
else if (length(grep("[^\\\\]\\[<-", pattern))) {
pattern <- sub("\\[<-", "\\\\\\[<-", pattern)
warning("replaced '[<-' by '\\\\[<-' in regular expression pattern")
}
}
grep(pattern, all.names, value = TRUE)
}
else all.names
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.