Skip to content

Commit

Permalink
beginning the move to knitr 1.6 and knitcitations 0.6.0 in preparatio…
Browse files Browse the repository at this point in the history
…n of rmarkdown
  • Loading branch information
trinker committed May 29, 2014
1 parent b8ddacb commit 27e8663
Show file tree
Hide file tree
Showing 18 changed files with 279 additions and 248 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ vignettes/NOTES
vignettes/TO_DO
vignettes/knitcitations.bib
vignettes/extra_functions.R
inst/staticdocs
inst/staticdocs
inst/build.R
11 changes: 7 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: reports
Type: Package
Title: An R package to assist in the workflow of writing academic articles and
other reports
Version: 0.2.0
Version: 0.3.0
Date: 2013-07-01
Author: Tyler Rinker
Maintainer: Tyler Rinker <tyler.rinker@gmail.com>
Expand All @@ -25,9 +25,10 @@ BugReports: http://github.com/trinker/reports/issues
LazyData: TRUE
VignetteBuilder: knitr
Depends:
R (>= 3.0.0)
R (>= 3.0.0),
qdapTools (>= 1.0.1)
Imports:
knitcitations (>= 0.5-0),
knitcitations (>= 0.6-0),
markdown,
slidify,
tools,
Expand All @@ -38,10 +39,12 @@ Suggests:
brew,
googleVis,
slidifyLibraries,
knitr,
knitr (>= 1.6),
xtable,
pander,
ProjectTemplate,
qdap,
reporttools,
rmarkdown,
sjPlot
Roxygen: list(wrap = FALSE)
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export(css_style_add)
export(css_style_change)
export(css_styles)
export(custom_css)
export(custom_pandoc_style)
export(delete)
export(doc_temp)
export(folder)
Expand All @@ -66,7 +67,6 @@ export(md2tex)
export(new_report)
export(new_vignette)
export(notes)
export(pad)
export(parenciteL)
export(parenciteM)
export(popup)
Expand Down Expand Up @@ -99,6 +99,7 @@ importFrom(XLConnect,appendWorksheet)
importFrom(XLConnect,loadWorkbook)
importFrom(XLConnect,saveWorkbook)
importFrom(markdown,markdownToHTML)
importFrom(qdapTools,pad)
importFrom(slidify,author)
importFrom(tools,file_ext)
importFrom(tools,file_path_sans_ext)
Expand Down
11 changes: 9 additions & 2 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ NEW FEATURES
* The sync family of functions has been introduced. These functions provide
quick syncing between directories. See `?sync` for more details.

* `custom_css` function for creating the components necessary for custom css
file for use with RStudio + knitr. See:
* `custom_css` and `custom_pandoc_style` functions for creating the components
necessary for custom css file for use with RStudio + rmarkdown + knitr. See:
http://www.rstudio.com/ide/docs/authoring/markdown_custom_rendering

* `css_styles` and `css_style_change` compliment `custom_css`. The former
Expand Down Expand Up @@ -213,6 +213,13 @@ CHANGES
* The NOTES.txt and TO_DO.txt files lose the file extensions to become NOTES and
TO_DO.

* `knitr 1.6` and `knitcitations 0.6.0` that incorporate the `rmarkdown` package
and utilize yaml + pandoc have significant changes. These changes are
reflected in the `reports` package.

* `pad` removed from reports package and added to `qdapTools` which is now
imported.


CHANGES IN reports VERSION 0.1.2
----------------------------------------------------------------
Expand Down
37 changes: 21 additions & 16 deletions R/BV.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,34 @@
#' the .bib file (working directory first and then "main_dir/REPORTS/_.bib",
#' last "main_dir/PRESENTATION/_.bib" in that order).
#' @param col.width An integer value of the maximum width of columns.
#' @return Returns a truncated view of user notes.
#' @return Returns a truncated view of user references (.bib file).
#' @export
#' @import knitcitations
#' @importFrom tools file_ext
#' @examples
#' ## BV()
BV <-
function(bib = NULL, col.width = 40) {
loc1 <- getwd()
loc2 <- file.path(loc1, "REPORT")
loc3 <- file.path(loc1, "PRESENTATION")
locs <- list(loc1, loc2, loc3)
FUN <- function(x) {
fls <- dir(file.path(x))
if (identical(fls, character(0))) return(NULL)
fls[file_ext(fls) == "bib"][1]
}
check <-lapply(locs, FUN)
test <- function(x) suppressWarnings((!is.null(x) & !is.na(x)))
x <- sapply(check, test)
x[sapply(x, identical, logical(0))] <- FALSE
mark <- which(unlist(x))[1]
bibloc <- file.path(locs[mark], FUN(locs[mark]))
if (is.null(bib)){
loc1 <- getwd()
loc2 <- file.path(loc1, "REPORT")
loc3 <- file.path(loc1, "PRESENTATION")
locs <- list(loc1, loc2, loc3)
FUN <- function(x) {
fls <- dir(file.path(x))
if (identical(fls, character(0))) return(NULL)
fls[file_ext(fls) == "bib"][1]
}
check <-lapply(locs, FUN)
test <- function(x) suppressWarnings((!is.null(x) & !is.na(x)))
x <- sapply(check, test)
x[sapply(x, identical, logical(0))] <- FALSE
mark <- which(unlist(x))[1]
bibloc <- file.path(locs[mark], FUN(locs[mark]))
} else {
bibloc <- bib
}

bibin <- suppressMessages(suppressWarnings(invisible(read.bibtex(bibloc))))
title <- sapply(bibin, function(x) {
tryCatch(clean(unlist(x)[grepl("\\.title", names(unlist(x)))]),
Expand Down
64 changes: 64 additions & 0 deletions R/custom_css.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,67 @@ css_style_add <- function(loc = QP("PRESENTATION/assets/css")) {
}
}


#' Generate Custom css for RStudio + knitr
#'
#' \code{custom_pandoc_style} - Generate the components necessary for a custom
#' pandoc styling for use with RStudio and knitr.
#'
#' @rdname custom_css
#' @export
custom_pandoc_style <-
function(rprofile = FALSE, loc = QP("REPORT"), source = TRUE) {

if (!is.null(loc)) {
if (!file.exists(loc)) {
stop(sprintf("%s does not exist", loc))
}
}

## Create the pandoc style
x <- c("options(rstudio.markdownToHTML =",
" function(inputFile, outputFile) { ",
" system(paste(\"pandoc\", shQuote(inputFile), \"-o\", shQuote(outputFile)))",
" }",
")\n"
)

if (!is.null(loc)) {
cat(paste(x, collapse = "\n"), file = file.path(loc, "style.R"))

## Direct where to change css options
message("Custom pandoc styling has been generated for your report.\n\n")
}

## Add style.R to .Rprofile for sourcing on load
if (rprofile) {
if (sum(dir(all.files = TRUE) == ".Rprofile") > 0) {

## Test if .Rprofile already contains the style.R function
RP <- gsub("\\s", "", paste(suppressWarnings(readLines(".Rprofile")),
collapse = ""))
XP <- gsub("\\s", "", paste(x, collapse=""))
if (!grepl(XP, RP, fixed = TRUE)) {
cat(paste(c("\n\n", x), collapse = "\n"), file = ".Rprofile",
append=TRUE)
} else {
warning(paste0(".Rprofile already contains style.R function:\n",
"`rprofile = TRUE` argument ignored"))
}
} else {
cat(paste(x, collapse = "\n"), file = ".Rprofile")
}
}

## Source it for the first time
if (source) {
options(rstudio.markdownToHTML =
function(inputFile, outputFile) {
system(paste("pandoc", shQuote(inputFile), "-o", shQuote(outputFile)))
}
)
}
}



37 changes: 0 additions & 37 deletions R/pad.R

This file was deleted.

1 change: 1 addition & 0 deletions R/rdirs.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#' \code{\link[base]{dir.create}}
#' @keywords file, directory, folder
#' @export
#' @importFrom qdapTools pad
#' @examples
#' ## fx <- folder(delete_me)
#' ## owd <- getwd(); setwd(fx)
Expand Down
4 changes: 2 additions & 2 deletions inst/CITATION
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ citEntry(entry = "manual",
author = "Tyler W. Rinker",
organization = "University at Buffalo/SUNY",
address = "Buffalo, New York",
note = "version 0.2.0",
note = "version 0.3.0",
year = "2013",
url = "http://github.com/trinker/reports",
textVersion = paste("Rinker, T. W. (2013).",
"reports: Package to assist in report writing.",
"version 0.2.0. University at Buffalo. Buffalo, New York.",
"version 0.3.0. University at Buffalo. Buffalo, New York.",
"http://github.com/trinker/reports")
)
30 changes: 30 additions & 0 deletions inst/build.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
curd <- getwd()
loc <- "C:/Users/trinker/Desktop"
setwd(loc)

qman <- function(x = "reports", db = "C:/Users/trinker/Dropbox/Public", dir=loc) {
path <- file.path(dir, paste0(x, ".pdf"))
if (!file.exists(path)) stop(paste(x, "does not exist..."))
opath <- file.path(db, paste0(x, ".pdf"))
file.copy(path, opath, overwrite = TRUE)
message("manual copied!\n")
}


repo <- pack <- "reports"
base.git = "C:/Users/trinker/GitHub"
quick = TRUE
library(devtools)

unlink(paste0(pack, ".pdf"), recursive = TRUE, force = TRUE)
x <- file.path(base.git, pack)
document(x)
install(x, quick = quick, build_vignettes = FALSE, dependencies = TRUE)

path <- find.package(pack)
system(paste(shQuote(file.path(R.home("bin"), "R")),
"CMD", "Rd2pdf", shQuote(path)))

qman(repo, dir=loc)
setwd(curd)
message("Done!")
36 changes: 25 additions & 11 deletions inst/extdata/vign_library/vignette_rmd/doc.Rmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
---
title: "vignette_name"
author: "name"
date: '`r Sys.Date()`'
output:
html_document:
css: assets/fix-bootstrap.css
toc: yes
pandoc_args: [
"--biblio", "references.bib",
"--csl", "ecology.csl"
]
---

<!--
%\VignetteEngine{knitr}
%\VignetteIndexEntry{A Markdown Vignette with knitr}
Expand All @@ -7,27 +21,27 @@
# set global chunk options
library(knitr)
opts_chunk$set(cache=FALSE)
library(knitcitations); library(reports)
#bib <- read.bibtex(dir()[tools::file_ext(dir()) == "bib"][1])
#cite in text using `r citet(bib[1])`
cleanbib()
options("citation_format" = "pandoc")
```
# vignette_name
## name
### `r as.character(format(Sys.Date(), "%m-%d-%Y"))`

To enable Markdown vignettes in an R package, you need to

- add `*.Rmd` files under the `inst/doc` or `vignettes` directory
- add `VignetteBuilder: knitr` to the `DESCRIPTION` file
- specify the vignette engine `\VignetteEngine{knitr}` in the `Rmd` files (inside HTML comments)

You can use your own CSS file instead of the built-in style in the **markdown** package -- just set the option `markdown.HTML.stylesheet`, e.g.
You can use your own CSS file instead of the built-in style in the **markdown** package -- just set the css in the yaml.

```{r css, echo = FALSE}
options(markdown.HTML.stylesheet = "css/style.css")
```

## References
```{r, echo=FALSE, results='asis'}
#bibliography("html")
```{r, echo=FALSE, message=FALSE}
#write.bibtex(file="references.bib")
```

```{r clean-up, include=FALSE}
# R compiles all vignettes in the same session, which can be bad
rm(list = ls(all = TRUE))
```
10 changes: 10 additions & 0 deletions inst/maintenance.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#========
# BUILD
#========
source("inst/build.R")

#==========================
# Run unit tests
#==========================
devtools::test()

#========================
# Delete manuals Rd files
#========================
Expand Down
2 changes: 1 addition & 1 deletion man/BV.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ last "main_dir/PRESENTATION/_.bib" in that order).}
\item{col.width}{An integer value of the maximum width of columns.}
}
\value{
Returns a truncated view of user notes.
Returns a truncated view of user references (.bib file).
}
\description{
Allows a truncated view of your .bib.
Expand Down
Loading

0 comments on commit 27e8663

Please sign in to comment.