R: Syntax Highlighter for R

highlight-package {highlight} | R Documentation

## Syntax Highlighter for R

### Description

Syntax highlighter for R based on output from the R parser

### See Also

The main function of the package is `highlight`.

`highlight` delegates rendering the document to `renderer`s, such as the `renderer_latex` or `renderer_html` and is helped by a detective to make sense of the results from the parser. The package ships a `simple_detective`.

The package also defines a custom sweave driver (`HighlightWeaveLatex`) for latex based on the standard sweave latex driver (`RweaveLatex`) using `highlight` to perform syntax highlighting of R code chunks.

### Examples

    ## Not run:
    tf <- tempfile()
    dump( "glm" , file = tf )

    # rendering in html
    highlight( tf, output = stdout(),
    	renderer = renderer_html() )

    # rendering in latex
    highlight( tf, output = stdout(),
    	renderer = renderer_latex() )

    # Sweave driver using syntax highlighting
    if( require( grid ) ){
    	v <- vignette( "grid", package = "grid" )$file
    	file.copy( v, "grid.Snw" )
    	Sweave( "grid.Snw", driver= HighlightWeaveLatex() )
    	system( "pdflatex grid.tex" )
    	if (.Platform$OS.type == "windows"){
    		shell.exec( "grid.pdf" )
    	} else {
    		system(paste(shQuote(getOption("pdfviewer")), "grid.pdf" ),
    			wait = FALSE)
    	}
    }

    unlink( tf )

    ## End(Not run)

[Package highlight version 0.4.7.2 Index]