# set global chunk options
library(knitr); library(qdapTools)
opts_chunk$set(cache=FALSE, tidy=FALSE, comment = NA)
options(xtable.type = 'html')
# library(googleVis)
#library(knitcitations); 
library(reports); library(pander); library(qdap); library(xtable)

#names(bib)
#write.bibtex(c(Yihui2013 = citation("knitr"), Boettiger2013 = citation("knitcitations"), 
#    Vaidyanathan2012=citation("slidify"), Rinker2013a = citation("qdap"), 
#   Rinker2013b = citation("reports"), Gesmann2011 = citation("googleVis")))
#bib <- read.bibtex("knitcitations.bib")

#names(bib)

BU <- "http://trinker.github.io/reports_dev/" #switch after push
LN <- function(fun, base=BU) paste0(BU, fun, ".html")
FUN <- function(fun, fun2 = fun, base=BU) HR2(LN(fun2), paste0("<code>", fun,"</code>"))
yt <- function(url) {
    paste0("<a href=\"", url, "\" target=\"_blank\" style=\"text-decoration: none\"><b><font size=\"5\" color=\"#B22222\">[YT]</font></b></a>\n")
}
#Reading in your own bib file:
#bib <- read.bibtex(getOption("bib.loc"))
#cite in text using `r citet(bib[1])`

reports Package Vignette

Tyler Rinker

The reports package (Rinker, 2013) is designed to bring together the best R has to offer in report writing in an intuitive fashion. The user houses everything related to the writing process in one accessible location. The reports package assists in writing reports and presentations by providing a frame work that brings together existing R, LaTeX/.docx and Pandoc tools. The package is designed to be used with RStudio, MikTex/Tex Live/LibreOffice, knitr, slidify, knitcitations, Pandoc and pander. The user will want to download these free programs/packages to maximize the effectiveness of the reports package.

The reports package assumes the user has some familiarity with the report writing programs/packages it depends on. For a complete list of reports dependencies r HR2("http://trinker.github.io/reports/dependencies", "click here"). This manual will not help the user to understand these dependencies as they have their own help documentation. Many functions in the reports package are set with defaults that assume the user is utilizing r HR2("http://www.rstudio.com/", "RStudio"). This vignette assumes that the user is also operating out of the root directory of the new_report/presentation in RStudio.

r IM("https://dl.dropboxusercontent.com/u/61803503/packages/reports.PNG", width=350, height=250)


Select from sections below:

    1. `r HR("#rprofile", "Setting Up .Rprofile ")`
    2. `r HR("#report", "Creating a New Report/Presentation ")`
    3. `r HR("#rep", "What's In the new_report/presentation Directory ")`
    4. `r HR("#code chunks", "Using reports Functions In-Text")`
    5. `r HR("#dir", "Directory Management ")`
    6. `r HR("#notes", "Using notes.xlsx ")`
    7. `r HR("#cite", "Citations ")`
    8. `r HR("#convert", "Document Conversion ")`
    9. `r HR("#html", "HTML Short Cuts")`
    10. `r HR("#temp", "Custom Reports Templates")`
    11. `r HR("#odd", "Odds and Ends")`
    `r HS(5)` A. `r HR("#odd1", "Reveal.js Slide Notes Locally")`
    `r HS(5)` B. `r HR("#odd2", "Custom style.css With RStudio + knitr")`
    `r HS(5)` C. `r HR("#odd3", "Presentations With slidify and RStudio")`
    Symbol Conventions:
    `r FT(gold, 5, text="♦")` = Example (R code)
    `r FT(firebrick, 5, text="[YT]")` = Video Demo (click to watch)



Setting Up .Rprofile

x <- readLines(n=8)
1. options(bib.loc = "C:/Users/trinker/Desktop/PhD Program/MASTER.bib")
2. options(name.reports = "Tyler Rinker\\\\University at Buffalo\\\\Department of Learning and Instruction")
3. options(sources.reports = path.expand("~/path_1"), path.expand("~/path_2"))
4. options(temp.reports = "apa6.mod.qual_tex")
5. options(github.user = "trinker")
6. options(speed.temp = list(`1` = "wordpress_web", `2` = "basic_web", `3` = "apa6.mod.qual_tex"))
7. options(present.template = "revealjs")
8. options(revealjs.loc = "C:/Users/trinker/Desktop/Copy/reveal.js")

x <- Trim(head(unname(unlist(genXtract(x, "(", " ="))), -1))
y <- left.just(data.frame(Option=x, Function=c("The path to the users primary .bib file (I store this in DropBox)", 
    "The name that will be automatically added to a report/presentation", 
    " Path(s) to additional scripts to be sourced on project startup",
    "The primary template to use to generate reports (see template)",
    "GitHub user name", "A speed dial like interface that allows the template argument to take a number")), 1)

print(xtable(y), type="html")

The user may want to set the following options in her r HR2("http://stat.ethz.ch/R-manual/R-patched/library/base/html/Startup.html", ".Rprofile"). This will add efficiency to your workflow. r yt("http://www.youtube.com/watch?v=oZrVlsWMDBc&feature=youtu.be")

Option Function
1 bib.loc The path to the users primary .bib file (I store this in DropBox)
2 name.reports The name that will be automatically added to a report/presentation
3 sources.reports Path(s) to additional scripts to be sourced on project startup
4 temp.reports The primary template to use to generate reports (see template)
5 github.user GitHub user name
6 speed.temp A speed dial like interface that allows the template argument to take a number
7 present.template Path to, or default, .Rmd file template for use in as the .Rmd used in the slidify presentations

r VS(2)

The following is the code I added to my own .Rprofile:

1. options(bib.loc = "C:/Users/trinker/Desktop/PhD Program/MASTER.bib")
2. options(name.reports = "Tyler Rinker\\\\University at Buffalo\\\\Department of Learning and Instruction")
3. options(sources.reports = path.expand("~/path_1"), path.expand("~/path_2"))
4. options(temp.reports = "apa6.mod.qual_tex")
5. options(github.user = "trinker")
6. options(speed.temp = list(`1` = "wordpress_rmd", `2` = "basic_rmd", `3` = "apa6.mod.qual_tex"))
7. options(present.template = "revealjs")


Creating a New Report/Presentation

Creating a new report or presentation directory is easy. r yt("http://youtu.be/XVdRT95k3wk") r VS(2)

The user can either preset the working directory or can supply a path to create the report/presentation directory in and then use the r FUN("new_report") or r FUN("presentation") functions. r VS(2)

setwd() method

setwd("C:/Users/trinker/Desktop")
new_report("MY REPORT")

path method

new_report("MY REPORT", path="C:/Users/trinker/Desktop")

You've just created your first report/presentation directory and you're ready to begin writing.

*Note The user can name the main directory differently from the names used within the directly by supplying a vector of length 2 to the report/presentation arguments as seen here:

new_report(c("Major1", "minor"))
presentation(c("Major2", "minor"))


What's In the new_report/presentation Directory

The directory created by the r FUN("new_report") or r FUN("presentation") functions houses multiple subdirectories and files that integrate to speed up work flow. Please see the following links for PDF descriptions of the contents of the reports/presentation directory. r VS(2)

Report
Workflow
Presentation Workflow

click here


click here


Using reports Functions In-Text

reports has a number of HTML shortcut functions that utilize two capital letters as names. These functions are ideally used in text with `r XX(args)`. Thus `r HR2("http://www.talkstats.com/")` yields:

r HR2("http://www.talkstats.com/")

This use does not require wrapping with cat or the print argument.

To better display the HTML code the following examples do not use r HR("#code chunks", "in-text") (in-line) coding. The examples use the following code chunk form (rarely used in an actual report):

```{r}
R_CODE(_HERE)
```

This means that wrapping with cat or the print argument are usually required, however, this is not typical in standard usage.


Directory Management

The reports package contains functions to help maintain directories. They can speed up workflow through automation of directory related tasks.

`r FUN("rdirs")`, `r HR2(LN("file_handling"), "folder")`, and `r HR2(LN("file_handling"), "delete")`

r FUN("rdirs") is a function designed to recursively create directories. This is particularly useful when used in combination with r FUN("new_report")/r FUN("presentation") for creating weekly lecture notes for a class or other similar repeated tasks. The following code chunks demonstrate uses for 3 directory management functions in the reports package:

  1. r FUN("rdirs") – recursive directory creation
  2. r HR2(LN("file_handling"), "folder") – create a directory
  3. r HR2(LN("file_handling"), "delete") – delete a directory(s)

*The next 5 code chunks are meant to be run sequentially

r FT(gold, 5, text="&diams;") Chunk 1- Create directory with multiple subdirectories r FT(gold, 5, text="&diams;")

fx <- folder(delete_me)
WD <- getwd()
setwd(fx)
rdirs(admin, 1:15, c("d", "f", "w"), c(1, 4, 6))

r FT(gold, 5, text="&diams;") Chunk 2- Return just the character vector. r FUN("rdirs") takes care of the front end padding of numbers. r FT(gold, 5, text="&diams;")

rdirs(admin, 1:15, c("d", "f", "w"), c(1, 4, 6), text.only = TRUE)

r FT(gold, 5, text="&diams;") Chunk 3- Create dated folders r FT(gold, 5, text="&diams;")

rdirs(session, 1:12, seq(as.Date("2000/1/1"), by = "month", length.out = 12))

r FT(gold, 5, text="&diams;") Chunk 4- Create director of subdirectories of working reports folders r FT(gold, 5, text="&diams;")

setwd(WD)
gx <- folder(delete_me2)
setwd(gx)
x <- rdirs(admin, 1:15, c("d", "f", "w"), c(1, 4, 6), text.only = TRUE)
lapply(x, new_report)

View it...

r FT(gold, 5, text="&diams;") Chunk 5- Clean up with r HR2(LN("file_handling"), "delete") and reset working directory r FT(gold, 5, text="&diams;")

delete(c(fx, gx))
setwd(WD)

Image File Synchronization `r yt("http://youtu.be/bhArI_dp4B8")`

The r HR2(LN("sync"), "sync family of functions") are also useful for syncing files between directories. This is particularly useful with the figure files in the REPORT and PRESENTATION directories and/or the img directory used by slidify (Vaidyanathan, 2012). The base version in the family, r FUN("sync") is generic and syncs files between 2 directories. The r HR2(LN("sync"), "sync_all") function is specifically designed to sync any files between the three image directories in a new_report/presentation directory.


To use r HR2(LN("sync"), "sync_all") simply type:

sync_all()

There are no arguments to sync_all, just run and the files between the following directories are synced:

  1. ~/REPORT/figure
  2. ~/PRESENTATION/figure
  3. ~/PRESENTATION/assets/img

Push Local Repo to GitHub

The user may choose to push a project (repository). The r FUN("repo2github") is designed for the initial push to github. Future pushes can be handled via RStudio or other git interface. The user may choose to initialize a push when r FUN("new_report") or r FUN("presentation") the project is created by adjusting the argument github = TRUE.


Using notes.xlsx

The notes.xlsx/notes.csv is a file located in the ARTICLES directory. It is useful to take notes from articles/websites/etc. and organize them here. The r FUN("notes") function can be used to view a truncated version of the notes. The citation functions also enables the user to insert in-text citations into a document with the quote taken from the article or other source. It is important that the format of notes.xlsx is respected in order for the r HR2(LN("cite"), "citation family") of functions to be utilized. In order for this workflow related to citations to be most effective the user must use a .bib file to manage citations. I use r HR2("http://jabref.sourceforge.net/", "JabRef") manage my bibliography. Here is a screen shot of notes.xlsx file.

r IM("myfigure/excel.png", 2, width=800, height=600)

notes.xlsx contains the following columns:

  1. Document (bib key) - The bib key from the .bib file (usually authorYEAR)
  2. Location (page) - The page number of the quote/passage (use an integer or integers separated by a dash)
  3. Gist/Quote - The quote or a gist of a passage
  4. Q - Is the row gist a quote? If so use b if not use n. Those marked y can be inserted as quotes into a document.
  5. Notes - An optional column to add notes to self

The Gist/QuoteQ should be written in r HR2("http://daringfireball.net/projects/markdown/syntax", "markdown")/html. The notes.xlsx file also contains a quick reference for html on the right side:

Format Text for notes.xlsx r yt("http://youtu.be/qtqpTGMKWd0") To assist in copying and pasting text from documents (particularly PDFs) the r FUN("QQ") (quick quote) takes a text string (optionally from the clipboard) and formats the text for use with notes.xlsx. Non-ascii characters (e.g. ligatures) and r HR2("http://stat.ethz.ch/R-manual/R-devel/library/base/html/Quotes.html", "**&#92;n**") are removed/converted (though the string should still be checked). By default the string is copied to the clipboard for easy pasting into notes.xlsx.


Citations

The reports package has an integrated system citation related functions that can be accessed in .tex, .Rnw and .Rmd documents.

The user can view the bibkey and document title of the references in the .bib files via the r FUN("BV") (bib view) function.

r FT(gold, 5, text="&diams;") Example r FT(gold, 5, text="&diams;")

head(BV())

  num bibkey           title                                   
1   1 Yihui20131       knitr: A general-purpose package for dyn
2   2 Yihui20132       Dynamic Documents with {R} and knitr    
3   3 Yihui20133       knitr: A Comprehensive Tool for Reproduc
4   4 Boettiger2013    knitcitations: Citations for knitr markd
5   5 Vaidyanathan2012 slidify: Generate reproducible html5 sli
6   6 Rinker2013a      {qdap}: {Q}uantitative Discourse Analysi

Citation Family of Functions The r HR2(LN("cite"), "citation family") of functions grab a quote and format the text taken from the notes.xlsx/notes.csv for LaTeX/.Rmd with optional citation included. Functions attempt to copy the output to the clipboard for easy paste inclusion.

Each of the functions in the cite family follow a pattern of (cite, parencite, textcite, posscite, poscite) prefix and (L or M) suffix (note that currently only parencite and textcite functions exist for markdown). The cite and textcite are in the form of LaTeX commands by the same name. posscite and poscite are user defined LaTeX function styles that are extensions of the textcite command to fit possessive and -s- ending possessives. They can be defined as:

\newcommand\posscite[1]{\citeauthor{#1}'s (\citeyear{#1})} 
\newcommand\poscite[1]{\citeauthor{#1}' (\citeyear{#1})}

The L and M correspond to LaTeX or markdown outputs; markdown relies on the r HR2("https://github.com/cboettig/knitcitations") (Boettiger, 2014) package.

r FT(gold, 5, text="&diams;") Example 1 - parenthesis cite r FT(gold, 5, text="&diams;")

parenciteM(1, force.block = FALSE)
 "An **EXAMPLE**; feel "free" to *delete* it ***soon***" ´r  citep("Rinker2013a")´

"An EXAMPLE; feel "free" to delete it soon" (Rinker, 2013b, p. 12)

r FT(gold, 5, text="&diams;") Example 2 - textcite r FT(gold, 5, text="&diams;")

textciteM(1, force.block = FALSE)
´r  citet("Rinker2013a")´ "An **EXAMPLE**; feel "free" to *delete* it ***soon***"

Rinker (2013b)"An EXAMPLE; feel "free" to delete it soon"

The LaTeX (L) versions of the functions work in a similar fashion but are used in .Rnw documents.


Updating .bib File r yt("http://youtu.be/XriSbJTXcZk")

The user may update the .bib files within the new_report/presentation created directories directly or may choose to update the master .bib file housed elsewhere (set with the bib.loc option in the r HR("#rprofile", ".Rprofile")). If the user opts for the second route the r FUN("update_bib") function will update all the .bib files in the respective directory(s) according to the master .bib file.


Document Conversion `r yt("http://youtu.be/OcaFub5OLSg")`

The r HR2("http://johnmacfarlane.net/pandoc/", "Pandoc") based file conversion family of functions use preset path defaults (default is REPORT directory) to enable the user to quickly convert between document types. The user must have Pandoc installed and on the OS path. The function names are intuitive with the portion before the 2 being the current document type and the portion after is the desired outcome document type (from2to). Here is an example, converting the doc.tex file from the reports package library directory to a .docx file (when the user is employing these functions it is not necessary to provide arguments).

r FT(gold, 5, text="&diams;") Example - file conversion r FT(gold, 5, text="&diams;")

DOC <- system.file("extdata/doc_library/apa6.qual_tex/doc.tex", package = "reports")
BIB <- system.file("extdata/docs/example.bib", package = "reports")
tex2docx(DOC, file.path(getwd(), "test.docx"), path = NULL, bib.loc = BIB)

*Note that all of the conversion functions can be used to convert any legitimate Pandoc conversion but if the from2to format is not followed the documents and paths must be explicitly supplied as arguments to the reports conversion function.


HTML Shortcuts

x <- structure(list(Code = structure(c(2L, 4L, 5L, 6L, 7L, 1L, 8L, 
    18L, 9L, 10L, 11L, 12L, 14L, 13L, 15L, 16L, 19L, 17L, 3L), .Label = c("BT", 
    "CN", "col2hex", "EM", "FT", "HR", "HR2", "HS", "IF", "IM", "IM2", 
    "IW", "PN", "RF", "SC", "TB", "VM", "VS", "YT"), class = "factor"), 
        HTML.Tag = structure(c(2L, 3L, 4L, 7L, 8L, 1L, 6L, 17L, 9L, 
        10L, 11L, 12L, 14L, 13L, 15L, 16L, 19L, 18L, 5L), .Label = c("button", 
        "courrier new", "email", "font", "hex colors", "horizontal space", 
        "hyperref", "hyperref (new window)", "iframe", "image", "image (short path)", 
        "image wrap", "presenter notes", "reveal fragment", "sprecial character", 
        "text box", "verticle space", "Vimeo", "YouTube"), class = "factor")), .Names = c("Code", 
    "HTML.Tag"), row.names = c(NA, -19L), class = "data.frame")
print(xtable(x), type="html", include.rownames=FALSE)

The general format of the HTML examples is:

(a) the display of the code used

(b) the HTML code produced

(c) the way the HTML renders in a browser.


This r HR("#tab", "table ") lists the HTML functions and the HTML tag types produced. Click on the left column function names to see a demonstration of its use.
r VS(2)

Code HTML Tag
`r HR("#CN", "CN")` courrier new
`r HR("#EM", "EM")` email
`r HR("#FT", "FT")` font
`r HR("#HL", "HL")` highlight text
`r HR("#HR", "HR")` hyperref
`r HR("#HR", "HR2")` hyperref (new window)
`r HR("#HR", "BT")` button
`r HR("#space", "HS")` horizontal space
`r HR("#space", "VS")` verticle space
`r HR("#iframe", "IF")` iframe
`r HR("#IM", "IM")` image
`r HR("#IM", "IM2")` image (short path)
`r HR("#IM", "IW")` image wrap
`r HR("#PN", "PN")` presenter notes
`r HR("#RF", "RF")` reveal.js fragment
`r HR("#SC", "SC")` sprecial character
`r HR("#TB", "TB")` text box
`r HR("#TB", "TB2")` writable text box
`r HR("#YT", "YT")` YouTube
`r HR("#YT", "VM")` Vimeo
`r HR("#col", "col2hex")` hex colors

r HR2(LN("CN"), "CN (courrier new)")

Wraps text with a courier new font tag. A specified version of r HR("#FT", "FT") but more convenient for constant use of courier new tags.

CN("new_report()")

r CN("new_report()")


r HR2(LN("EM"), "EM (email)")

Wrap an email to generate an HTML email tag.

EM("tyler.rinker@gmail.com", print = TRUE)
EM("tyler.rinker@gmail.com", print = TRUE)

r HR2(LN("FT"), "FT (font)")

Wraps text with a font tags. Conveniently detects c(face, size` and/or color) and creates a font tag with the supplied text.

r FT(gold, 5, text="&diams;") Example 1 r FT(gold, 5, text="&diams;")

FT(6, text="guy")
FT(6, text="guy")

r FT(gold, 5, text="&diams;") Example 2 r FT(gold, 5, text="&diams;")

FT(6, blue, text="guy")
FT(6, blue, text="guy")

r FT(gold, 5, text="&diams;") Example 3 r FT(gold, 5, text="&diams;")

FT(6, red, times_new_roman, text="guy")
FT(6, red, times_new_roman, text="guy")

r HR2(LN("HL"), "HL (highlight text)")

r FT(gold, 5, text="&diams;") Example 1 r FT(gold, 5, text="&diams;")

cat(HL("Do not trust robots!"), "They are bent on destruction.")
cat(HL("Do not trust robots!"), "They are bent on destruction.") 

r FT(gold, 5, text="&diams;") Example 2 r FT(gold, 5, text="&diams;")

cat(HL("Jake is a cookie scientist,", color="pink"), "an honorable profession.")
cat(HL("Jake is a cookie scientist,", color="pink"), "an honorable profession.")

r HR2(LN("hyperref"), "HR/HR2/BT (hyperrefs and buttons)")

Convert path/url to HTML href tag.

  1. HR - Wrap a path/url to generate an HTML href tag.
  2. HR2 - Convenience version of HR that opens in a new page.
  3. BT - Wrap a path/url to generate an HTML hyperlinked text button tag.

r FT(gold, 5, text="&diams;") Example 1 - HR demo: no text given--r HR("http://stat.ethz.ch/R-manual/R-patched/library/base/html/basename.html", "basename") used; opens in same window r FT(gold, 5, text="&diams;")

HR(path="http://dl.dropbox.com/u/61803503/Likert.pdf", print = TRUE)  
HR(path="http://dl.dropbox.com/u/61803503/Likert.pdf", print = TRUE)  

r FT(gold, 5, text="&diams;") Example 2 - HR demo: no text given--r HR("http://stat.ethz.ch/R-manual/R-patched/library/base/html/basename.html", "basename") used; opens in same window r FT(gold, 5, text="&diams;")

HR("http://cran.r-project.org/", print = TRUE) 
HR("http://cran.r-project.org/", print = TRUE) 

r FT(gold, 5, text="&diams;") Example 3 - HR demo: text given; opens in same window r FT(gold, 5, text="&diams;")

HR("http://www.rstudio.com/ide/download/desktop", "click me", print = TRUE)  
HR("http://www.rstudio.com/ide/download/desktop", "click me", print = TRUE)

r FT(gold, 5, text="&diams;") Example 4 - HR2 demo: text given; opens in new window r FT(gold, 5, text="&diams;")

HR2("https://github.com/trinker/reports", "reports", print = TRUE)  
HR2("https://github.com/trinker/reports", "reports", print = TRUE) 

r FT(gold, 5, text="&diams;") Example 5 - BT demo r FT(gold, 5, text="&diams;")

BT("http://trinker.github.io/reports/dependencies", "Click Here!", print = TRUE)
BT("http://trinker.github.io/reports/dependencies", "Click Here!", print = TRUE)

r HR2(LN("space"), "HS/VS (spaces)")

Insert n iterations of HTML spacing into a document.

r FT(gold, 5, text="&diams;") Example 1 - HS demo r FT(gold, 5, text="&diams;")

cat(paste0("reports", HS(10), "end"))
cat(paste0("reports", HS(10), "end")); cat(VS())

r FT(gold, 5, text="&diams;") Example 2 - VS demo: single space r FT(gold, 5, text="&diams;")

cat(paste0("the", VS(), "end"))
cat(paste0("the", VS(), "end")); cat(VS()) 

r FT(gold, 5, text="&diams;") Example 3 - HS demo: multiple spaces r FT(gold, 5, text="&diams;")

cat(paste0("the", VS(3), "end"))
cat(paste0("the", VS(3), "end")); cat(VS()) 

r HR2(LN("IF"), "IF (iframe embedding)")

Wrap a url to generate an HTML iframe tag.

r FT(gold, 5, text="&diams;") Example 1 r FT(gold, 5, text="&diams;")

IF("https://dl.dropboxusercontent.com/u/61803503/MWE.html", print = TRUE, height=250)
IF("https://dl.dropboxusercontent.com/u/61803503/MWE.html", print = TRUE, height=250)

r FT(gold, 5, text="&diams;") Example 2 r FT(gold, 5, text="&diams;")

IF("http://www.online-stopwatch.com/countdown-clock/full-screen/", height=400, center = TRUE, print = TRUE)
IF("http://www.online-stopwatch.com/countdown-clock/full-screen/", height=400, center = TRUE, print = TRUE)

r FT(gold, 5, text="&diams;") Example 3 r FT(gold, 5, text="&diams;")

IF("http://www.dosketch.com/", width=1100, height=650, print=TRUE)
IF("http://www.dosketch.com/", width=1100, height=650, print=TRUE)

r FT(gold, 5, text="&diams;") Example 4 r FT(gold, 5, text="&diams;")

IF("http://glimmer.rstudio.com/pssguy/TVShowRatings/", width="100%", height=650, print=TRUE)
IF("http://glimmer.rstudio.com/pssguy/TVShowRatings/", width="100%", height=650, print=TRUE)

r FT(gold, 5, text="&diams;") Example 5 r FT(gold, 5, text="&diams;")

IF("https://dl.dropboxusercontent.com/u/61803503/Slides/reports/index.html", width=1150, height=750, print=TRUE)
IF("https://dl.dropboxusercontent.com/u/61803503/Slides/reports/index.html", width=1150, height=750, print=TRUE)

r FT(gold, 5, text="&diams;") Example 6 Here's an example of embedding a beautiful interactive visualization compliments of the googleVis package (Gesmann & Castillo, 2011) r FT(gold, 5, text="&diams;")

IF("https://dl.dropboxusercontent.com/u/61803503/presentations/tmp.html", width=770, height=680, print=TRUE)
IF("https://dl.dropboxusercontent.com/u/61803503/presentations/tmp.html", width=770, height=680, print=TRUE)

r HR2(LN("image"), "IM/IM2/IW (images and text-wrapped images)")

These functions generate an HTML image tag that embeds an image. IM2 not demonstrated as this function assumes local image source.

  1. IM - Wrap a path/url to generate an HTML tag. Often markup code: ![](url( lacks flexibility with centering and sizing. IM enables control of centering via altering the sty/center commands and control of sizing via the numeric values supplied to height and width.
  2. IM2 - A wrapper for IM that sets the base path to "assets/img/". This allows the users to just specify the image name that resides in one of the following directories: 1-"~/assets/img" or 2-"~/figure".
  3. IW - Text wrapped images.

r FT(gold, 5, text="&diams;") Example 1 - IM demo: Use width=NULL to retain original size r FT(gold, 5, text="&diams;")

IM("http://cran.r-project.org/Rlogo.jpg", width=NULL, print=TRUE)
IM("http://cran.r-project.org/Rlogo.jpg", width=NULL, print=TRUE)

r FT(gold, 5, text="&diams;") Example 2 - IM demo: uses default width = 540, height = IE(width, 360) to size r FT(gold, 5, text="&diams;")

IM("https://dl.dropboxusercontent.com/u/61803503/packages/reports.PNG", print=TRUE)
IM("https://dl.dropboxusercontent.com/u/61803503/packages/reports.PNG", print=TRUE)

r FT(gold, 5, text="&diams;") Example 3 - IM demo: hyperlinked image r FT(gold, 5, text="&diams;")

IM("http://cran.r-project.org/Rlogo.jpg", NULL, print=TRUE, link = "http://cran.r-project.org")
IM("http://cran.r-project.org/Rlogo.jpg", NULL, print=TRUE, link = "http://cran.r-project.org")

r FT(gold, 5, text="&diams;") Example 4 - IM demo: assumed image directory r FT(gold, 5, text="&diams;")

IM2("Rlogo.jpg", center=FALSE)
IM2("Rlogo.jpg", loc=2, center=FALSE)

r FT(gold, 5, text="&diams;") Example 5 - IW demo: text wrapped image with hyperlink r FT(gold, 5, text="&diams;") r VS(2)

`r IW("http://www.talkstats.com/images/misc/logo.png", "http://www.talkstats.com/", width=140, height=75)`

## <a href="http://www.talkstats.com/" target="_blank"><img src="http://www.talkstats.com/images/misc/logo.png" width="140" height="75"></a>
`r IW("http://www.talkstats.com/images/misc/logo.png", "http://www.talkstats.com/", width=140, height=75)` So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text! So much text!

r HR2(LN("PN"), "PN (presenter notes)")

Creates presenter notes (an aside of the class "notes") for slides (e.g., reveal.js slides). Multiline notes can be supplied with \n separating the lines or on separate lines as seen below.

r FT(gold, 5, text="&diams;") Example 1 - single line r FT(gold, 5, text="&diams;")

PN("some fancy notes", print = TRUE)
PN("some fancy notes", print = TRUE)

r FT(gold, 5, text="&diams;") Example 2 - multiline with \n as separator r FT(gold, 5, text="&diams;")

PN("1) some\n2) fancy\n3) notes", print = TRUE)
PN("1) some\n2) fancy\n3) notes", print = TRUE)

r FT(gold, 5, text="&diams;") Example 3 - multiline on separate lines r FT(gold, 5, text="&diams;")

PN("1) some
2) fancy
3) notes", print = TRUE)

PN("1) some 
2) fancy 
3) notes", print = TRUE)
PN("1) some 
2) fancy 
3) notes", print = TRUE)

r HR2(LN("RF"), "RF (reveal.js fragments)")

Slidify uses to include animated fragments (see r HR2("https://github.com/ramnathv/slidifyExamples/blob/gh-pages/examples/revealjs/index.Rmd", "this example")) in reveal.js slides. This is required per each slide. Using `r RF()` reduces the typing involved with this action.

RF()

r HR2(LN("SC"), "SC (special character)")

The general use of SCis to provide a character string of length 2. The first character is a letter and the second is one of the following symbols (left column) and HTML equivalent (right column):

x <- data.frame(Key = c('apostrophe', 'back tick', 'colon', 'tilde', 'carat', 'slash', 'lowercase o', 'comma'), Symb=c("'", "&#96;", ":", "~", "^", "/", "o", ","), HTML=c("acute", "grave", "uml", "tilde", "circ", "slash", "ring", "cedil") )

print(xtable(x), type="html", include.rownames=FALSE)
Key Symb HTML
apostrophe ' acute
back tick ` grave
colon : uml
tilde ~ tilde
carat ^ circ
slash / slash
lowercase o o ring
comma , cedil

The user can create non-HTML characters with SC that will not be converted (i.e., SC("b~") would yield "&btilde;" and would not be converted appropriately).

SC("A'")
SC('a\'')  #can use single quotes with escape 
SC("a`")
SC("n~")
SC("o:")
SC("(c)")
SC("(r)")
SC("c|")
SC("o/")
SC("ao")
SC("c,")
SC("p") 
SC("P") 
SC("E")
SC("Y")
SC("/")
SC("+-")
SC("L")
SC("tm") 
SC("S") 
SC("<") 
SC(">") 
SC("~")
SC("o")

r HR2(LN("TB"), "TB (text box)")

Wrap text to generate an HTML text box tag. r FUN("TB") is a traditional text box using div tags whereas r FUN("TB2", "TB") is a writable text box.

r FT(gold, 5, text="&diams;") Example 1 r FT(gold, 5, text="&diams;")

TB("I like ice cream!", print=TRUE)
TB("I like ice cream!", print=TRUE)

r FT(gold, 5, text="&diams;") Example 2 r FT(gold, 5, text="&diams;")

TB("Free cookies for a year!", col = "red", font.col="white", print=TRUE)
TB("Free cookies for a year!", col = "red", font.col="white", print=TRUE)

r FT(gold, 5, text="&diams;") Example 3 r FT(gold, 5, text="&diams;")

TB2("I like ice cream!", print=TRUE)
TB2("I like ice cream!", print=TRUE)

r FT(gold, 5, text="&diams;") Example 4 r FT(gold, 5, text="&diams;")

TB2("Free cookies for a year!", print=TRUE)
TB2("Free cookies for a year!", print=TRUE)

r HR2(LN("video"), "YT/VM (insert video)")

Returns a character vector of an HTML iframe tag that embeds a YouTube or Vimeo video.

r FT(gold, 5, text="&diams;") Example 1- YouTube using url tag r FT(gold, 5, text="&diams;")

YT("ArHQjQyIS70", print = TRUE)
YT("ArHQjQyIS70", print = TRUE)

r FT(gold, 5, text="&diams;") Example 2- YouTube using full url r FT(gold, 5, text="&diams;")

YT("http://www.youtube.com/watch?v=ArHQjQyIS70", print = TRUE)
YT("http://www.youtube.com/watch?v=ArHQjQyIS70", print = TRUE)

r FT(gold, 5, text="&diams;") Example 3- Vimeo video r FT(gold, 5, text="&diams;")

VM("http://vimeo.com/54007714", print = TRUE)
VM("http://vimeo.com/54007714", print = TRUE)

r HR2(LN("col2hex"), "col2hex (colors)")

Convert R colors() to Hexadecimal.

col2hex("darkblue")
col2hex(c("darkblue", "red"))
cat(paste0("<hr color=\"", col2hex("red"), "\" size=\"4\">"))
cat(paste0("<hr color=\"", col2hex("red"), "\" size=\"4\">"))


Custom Templates r yt("http://youtu.be/CMmHOvMrEvQ")

The user can create a document template framework for template personal use or submission with the r FUN("doc_temp") function. This function generates a document template for personal use or submission to the reports package to be included as a template in the doc_library. This function is similar to package.skeleton.


Odds and Ends

Reveal.js Slide Notes Locally (No Internet Connection)

Often you may find yourself in situations in which you have no Internet access. The slide notes in Reveal.js depend upon the presentation being hosted on a server, otherwise the notes will be inaccessible. However, setting up a local host enables viewing slide notes without an Internet connection. This can be accomplished via Python.

Before a Reveal.js presentation can be shown the user must:

Install r HR2("http://www.python.org/", text="Python") and make it accessible from the command line r yt("http://youtu.be/VlqpiKHz7Gw")

The user may then click on the bash/batch file generated by r FUN("local_host") and run the presentation locally. r yt("http://youtu.be/sg_lKU3n-co") (note that this file must be clicked on outside of RStudio or the user may use FUN("run_lh", "local_host") to create and run the local host). The bash/batch file that is generated automatically creates a local host and opens the directory of the presentation for automatic access to locally hosted presentations.

Conversely, the user may want to operate from the command line. If this approach is used the following must be conducted each time you want show a presentation locally. r yt("http://youtu.be/6VRMcHyXEKc")
1. Open the command line and change the directory to the Reveal.js HTML presentation
2. Run python -m SimpleHTTPServer in the command line
3. Use http://localhost:8000/THE_NAME OF_REVEALJS_PRESENTATION.html in the browser url bar

Special Thanks to Dason Kurkiewicz and Ramnath Vaidyanathan for working the local host out.


Custom style.css With RStudio + knitr `r yt("http://youtu.be/WkwVb2uOBLM")`

When using r HR2("http://yihui.name/knitr/", "knitr") with RStudio's r CN("Knit HTML") button a standard style.css file is utilized and thus control over aesthetics of the document is limited. The r FUN("custom_css") provides the frame work (generates ~css/style.css and style.R files in the correct places) that allows a r HR2("http://www.rstudio.com/ide/docs/authoring/markdown_custom_rendering", "custom style.css file") to be used with RStudio + knitr. The user simply runs:

custom_css()

After the appropriate files are created the user adds custom styling to the ~/css/style.css. The user has to source before the custom styles will be applied. The user may specify r CN("rfprofile = TRUE") in r FUN("custom_css") to add the style.R to the .Rprofile for sourcing upon startup. Otherwise, the user must open the style.R as the active tab in RStudio, check the Source on Save box and the click the save icon.

Note that the path to a style.css can be supplied to r FUN("custom_css") via the r CN("style.css") argument. This may be a user defined file or an internal file from the reports style.css library (see r FUN("css_styles", "custom_css")). For examples see: r HR2("https://github.com/trinker/style.css_examples", "https://github.com/trinker/style.css_examples"). Feel free to submit your own style.css to the reports package <reports.rpackage@gmail.com> marked with style.css template in the subject line.


Presentations (`r HR2("http://www.rstudio.com/ide/docs/presentations/overview", "RStudio's .Rpres")` and `r HR2("http://slidify.org/", "Slidify")` (Vaidyanathan, 2012))

The reports package relies on the flexible r HR2("http://slidify.org/", "slidify package") and lightweight r HR2("http://www.rstudio.com/ide/docs/presentations/overview", "RStudio's .Rpres") framework for presentation generation. For possible slidify templates that can be supplied to r FT(green, courier_new, text="present") in project generating functions use the r FUN("slidify_templates") function (for the RStudio .Rpres option use r FT(green, courier_new, text="present = \"rstudio\"")). For slidify examples see: https://github.com/ramnathv/slidifyExamples. The user will want to become familiar with both of these presentation approaches.


Acknowledgements

The reports package is just a collection of the best R tools. A special thanks to r HR2("http://yihui.name/", "Yihui") Xie (2013) for his work with the r HR2("http://yihui.name/knitr/", "knitr package") and r HR2("http://people.mcgill.ca/ramnath.vaidyanathan/", "Ramnath Vaidyanathan") for his r HR2("http://slidify.org/", "slidify package"). These R packages are the core of the reports package. For a complete list of reports dependencies r HR2("http://trinker.github.io/reports/dependencies", "click here").


options(markdown.HTML.stylesheet = "css/style.css")

References

# R compiles all vignettes in the same session, which can be bad
rm(list = ls(all = TRUE))


trinker/reports documentation built on May 31, 2019, 9:51 p.m.