Testing highlight.js with r code

(This article was first published on jkunst.com: Entries for category R, and kindly contributed to R-bloggers)

I searched for a javascript plugin to highlighter code, but obviously not any code. I needed to higlight R. Finally I founded highlight.js. Highlights.js is pretty cool for many reasons. I like Highlights.js because:

  1. Support R lenguage.
  2. It's easy to use. Works automatically. That's mean you don't have to put the code what are you writing. Highloght it does alone.
  3. A lot of styles.
  4. And yep! Again! Support R lenguage.

centre <- function(x, type, ...) {
         mean = mean(x),
         median = median(x),
         trimmed = mean(x, trim = .1))

foo "bar" baz
# test "test"
"test # test"

And an example of python code:

def cov(x,y):
    n = len(x)
    xmn = mean(x)
    ymn = mean(y)
    xdeviations = [0]*len(x)
    ydeviations = [0]*len(y)
    for i in range(len(x)):
        xdeviations[i] = x[i] - xmn
        ydeviations[i] = y[i] - ymn
    ss = 0.0
    for i in range(len(xdeviations)):
        ss = ss + xdeviations[i]*ydeviations[i]
    return ss/float(n)
def cor(x,y):
    return cov(x,y)/(var(x)*var(y))**.5


To leave a comment for the author, please follow the link and comment on his blog: jkunst.com: Entries for category R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.