Skip to content

Instantly share code, notes, and snippets.

@HenrikBengtsson
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HenrikBengtsson/f4e8f6fe2af5d6ccbed6 to your computer and use it in GitHub Desktop.
Save HenrikBengtsson/f4e8f6fe2af5d6ccbed6 to your computer and use it in GitHub Desktop.
RSP example: A Table
<%--------------------------------------------------------------
Usage:
md <- R.rsp::rfile('table-pandoc.md.rsp', postprocess=FALSE)
pdf <- gsub("md$", "pdf", md)
system2("pandoc", args=c(normalizePath(md), "-o", pdf))
!pdf # Opens PDF in viewer
Requires Pandoc [http://johnmacfarlane.net/pandoc/] and
LaTeX, because Pandoc uses LaTeX to generate PDFs.
--------------------------------------------------------------%>
<%
R.utils::use("knitr")
options(knitr.table.format="pandoc")
kable <- function(...) print(knitr::kable(...))
%>
# A Table
<%
data <- head(datasets::iris)
%>
<% kable(data) %>
_Table: The first <%=nrow(data)%> entries of the iris dataset._
<%--------------------------------------------------------------
Usage:
html <- R.rsp::rfile('table.md.rsp')
!html # Opens HTML in browser
Test on the fly (no installation required):
source("http://callr.org/rfile#https://gist.githubusercontent.com/HenrikBengtsson/f4e8f6fe2af5d6ccbed6/raw/table.md.rsp")
!html
--------------------------------------------------------------%>
<%
R.utils::use("knitr")
options(knitr.table.format="markdown")
kable <- function(...) print(knitr::kable(...))
%>
# A Table
<%
data <- head(datasets::iris)
%>
<% kable(data) %>
_Table: The first <%=nrow(data)%> entries of the iris dataset._
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment