Syntax Highlighting for R Source Code

Provides syntax highlighting for R source code. Currently it supports LaTeX and HTML output. Source code of other languages is supported via Andre Simon's highlight package ( http://www.andre-simon.de).


This is an infrastructure R package for syntax highlighting. It supports LaTeX and HTML output. Not surprisingly, it works best with R code. It attaches markups onto source code, e.g., it turns

a <- 1 # something

into LaTeX code

\hlstd{a} \hlkwb{<-} \hlnum{1} \hlcom{\# something}

or HTML code

<span class="hl std">a</span> <span class="hl kwb">&lt;-</span> <span class="hl num">1</span> <span class="hl com"># something</span>

via

library(highr)
hi_latex("a <- 1 # something")
hi_html("a <- 1 # something")
# or hilight(code, format = "latex"/"html")

This package also has a wrapper function, hi_andre(), for Andre Simon's Highlight package.

There are a few package Markdown vignettes in this package:

browseVignettes(package = "highr")

To install the development version here, use

install.packages('highr', repos = 'http://rforge.net', type = 'source')

This package is licensed under GPL, and is supposed to serve other packages such as knitr.

News

    CHANGES IN highr VERSION 0.6

NEW FEATURES

o `hilight()` can deal with multibyte characters that cannot represented in
the system native encoding now (on Windows)

BUG FIXES

o blank lines before/after code are preserved in the hilight() output now
(thanks, Terry Therneau)

    CHANGES IN highr VERSION 0.5

MAJOR CHANGES

o the minimal required R version is 3.0.2 now

    CHANGES IN highr VERSION 0.4

BUG FIXES

o hi_andre() may fail to find highlight under OS X (thanks, Christopher Gandrud, #2)

MINOR CHANGES

o :: and ::: are recognized as operators, and they will be syntax highlighted in the same way as other operators like +, -, *, and /, etc (thanks, Qiang Li, #3)

    CHANGES IN highr VERSION 0.3

BUG FIXES

o blank lines were not preserved in previous versions; now they can be correctly preserved

o hilight() works when the code is only a comment; fixed the bug reported at http://stackoverflow.com/q/18548020/559676 which was actually due to the bug of utils::getParseData() in R 3.0.1

o Linux Mint has a built-in version of highlight under /usr/local/bin/ which is not Andre Simon's highlight, and this can hang highr (https://groups.google.com/forum/#!topic/knitr/nicYgzqhwX8)

MINOR CHANGES

o the package vignettes were built with the knitr::docco_classic engine; see vignette(package = 'highr')

    CHANGES IN highr VERSION 0.2.1

MINOR CHANGES

o fixed a test that failed under R 2.15.x due to the keep.source argument in parse(), which was not available in R until R 3.0.0

    CHANGES IN highr VERSION 0.2

NEW FEATURES

o added a new argument 'fallback' in hilight(); for R < 3.0.0, we can use hilight(..., fallback = TRUE), which is a rough syntax highlighting method based on regular expressions (hence less accurate and comphrehensive than the getParseData() approach); as a result, highr no longer has to depend on R 3.0.0, although it is recommended to use R 3.0.0

    CHANGES IN highr VERSION 0.1

NEW FEATURES

o the first version of highr: a hilight() function based on utils::getParseData() to do syntax highlighting for R code; hi_andrew() as a wrapper for Andre Simon's Highlight package

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("highr")

0.6 by Yihui Xie, 2 years ago


https://github.com/yihui/highr


Report a bug at https://github.com/yihui/highr/issues


Browse source code at https://github.com/cran/highr


Authors: Christopher Gandrud [ctb], Qiang Li [ctb], Yixuan Qiu [aut], Yihui Xie [aut, cre]


Documentation:   PDF Manual  


Task views: Reproducible Research


GPL license


Suggests knitr, testit


Imported by explor, knitr, questionr.

Suggested by manifestoR, repr.


See at CRAN