Last active
December 27, 2015 00:09
-
-
Save jpritikin/7235206 to your computer and use it in GitHub Desktop.
knitr doesn't generate the figure correctly when knit_hooks$set is enabled in the shell script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -o errexit | |
set -o nounset | |
set -o noclobber | |
name=predis-sm | |
R --no-save --restore <<'EOF' | |
library(knitr) | |
opts_knit$set(error=TRUE) | |
opts_chunk$set(echo=FALSE, cache=TRUE) | |
if(1) { | |
knit_hooks$set(inline=function (x) { | |
if (any(is.na(x))) return(paste("\\textbf{TODO}\\todo{Sexpr evaluated to NA}")) | |
if (is.numeric(x)) | |
x = round(x, getOption("digits")) | |
paste(as.character(x), collapse = ", ") | |
}) | |
} | |
library(ggplot2) | |
update <- function(stem) { | |
rnw <- paste(stem,"Rnw",sep='.') | |
# if (file.info(rnw)$mtime > file.info(paste(stem,"tex",sep='.'))$mtime) { | |
knit(rnw) | |
# } | |
} | |
update("predis-sm") | |
EOF | |
[ -d gen ] || mkdir gen | |
pdflatex -shell-escape $name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{article} | |
\usepackage[backgroundcolor=yellow,shadow,textwidth=1in]{todonotes} | |
\begin{document} | |
<<cache=FALSE>>= | |
if (length(ls())) rm(list=ls()) # new section | |
opts_chunk$set(fig.path="figure/intro/") | |
@ | |
\begin{figure} | |
<<fig.height=3>>= | |
plot(sin) | |
@ | |
\caption{Empirical response} | |
\end{figure} | |
Much work remains \Sexpr{NA}, but I have already begun to use OpenMx | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
opts_knit$set(error=TRUE)
should beopts_chunk$set(error=TRUE)