sweave

Set directory of files created by a shell script?

你离开我真会死。 提交于 2019-12-12 04:41:27
问题 EDIT: had to retag this, because, it's rather a Sweave / R question since the problem of this script is the output directory of the Sweave Code. Is there a corresponding option for R CMD Sweave ? I have a shell script that creates a .tex file from a .Rnw file. This file needs to be processed further, but is not found by the script because it's somehow automatically generated to my Home directory. I need the .tex file to be generated in the folder of the .Rnw file (because all the other

Compile .Rnw file with command

一笑奈何 提交于 2019-12-12 03:19:10
问题 I have .Rnw file which generates me a report. In RStudio you compile it with button 'Compile PDF'. But is there a way to compile this file with command in script and pass one character variable? I tried to use function knit() but it only produces .tex file and I would like to obtain also pdf. Thanks for your help in advance! 回答1: The function knit2pdf in the knitr package does the trick ;) 来源: https://stackoverflow.com/questions/32115713/compile-rnw-file-with-command

knitr: Chapter name is the name of R chunk code

余生长醉 提交于 2019-12-11 06:29:23
问题 I want to use the R chunk code output as the Chapter Name but could not figured out how to do this. Below is my minimum working example. \documentclass{book} \usepackage[T1]{fontenc} \begin{document} \chapter{cat( << label=Test1, echo=FALSE, results="asis">>= 2+1 @ ) } Chapter name is the output of R chunk Code. \end{document} 回答1: This works for me << label=Test1, echo=FALSE>>= cn <- 2+1 @ \chapter*{Chapter \Sexpr{cn}} 回答2: In RMarkdown you can use the following code # `r I(1+2)` 来源: https:/

Pass two set of rules for rows to xtable

北慕城南 提交于 2019-12-11 05:07:50
问题 Please consider the following MWE (variation from this answer) \documentclass[a4paper]{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[english]{babel} \usepackage{booktabs} \usepackage{colortbl, xcolor} \begin{document} <<do_table, results = "asis">>= library(xtable) mydf <- data.frame(id = 1:10, var1 = rnorm(10), var2 = runif(10)) rws <- c(1,3,5,6,7) col <- rep("\\rowcolor[gray]{0.95}", length(rws)) print(xtable(mydf), booktabs = TRUE, add.to.row = list(pos = as

Using graphicspath in latex/sweave

自作多情 提交于 2019-12-11 02:52:50
问题 I have an Sweave file, where I need to embed a png and pdf from another folder. This is how I tried it \usepackage{graphicx} \graphicspath{{inst/extdata/}} \DeclareGraphicsExtensions{.pdf,.png} \begin{document} \begin{figure} \includegraphics[scale=0.7]{image.png} \caption{captionA} \label{fig:labelA} \end{figure} I also tried like this, but this didn't work: \graphicspath{{filePath}} filePath = "C:/path" \begin{figure} \includegraphics[scale=0.7]{image.png} \caption{captionA} \label{fig

Custom output hooks in knitr

落花浮王杯 提交于 2019-12-11 02:40:02
问题 I am trying to create a chunk hook that can produce a \floatfoot{} as part of the output from a chunk. Hopefully the following example makes clear what I am trying to achieve: 1. .Rnw file Here is the knitr file. \documentclass[a4paper]{article} \title{Learn Moar knitr!} \author{Foo Bar} \date{\today} \usepackage{blindtext} \usepackage{floatrow} \begin{document} \blindtext <<label=plotWithNotes, fig.lp='fig:', fig.cap='This is a figure'>>= plot(rnorm(100), rbinom(n = 100, size = 1, prob = 0.5

R/Sweave/Latex - Place comment in table (xtable)

浪尽此生 提交于 2019-12-11 02:25:39
问题 I created a table using R and sweave in LaTeX. A sweave example: \documentclass{article} \begin{document} \SweaveOpts{concordance=TRUE} <<label=tab1, echo=FALSE, results=tex>>= library(xtable) employee <- c('John Doe','Peter Gynn','Jolie Hope') salary <- c(21000, 23400, 26800) mData <- data.frame(employee, salary) print(xtable(mData, caption = "Salary", align="ccc"), caption.placement="top", hline.after = c(c(-1, 0), nrow(mData)), include.rownames=FALSE) @ \end{document} The basic LaTeX

Format inline output conditional on textual context

别来无恙 提交于 2019-12-11 02:04:13
问题 Using a modification (adapted from Jason French's blog post here) to the default inline knitr hook, I am printing numeric output rounded to 3 decimal places. If the value is less than 0.001, it returns "< 0.001". Here's an MWE showing the hook modification, and how I might use it in practice in R Markdown: ```{r setup, echo=FALSE} library(knitr) inline_hook <- function(x) { if (is.numeric(x)) { res <- ifelse(x == round(x), sprintf("%d", x), sprintf("%.3f", x) ) res <- ifelse(x < 0.001, '< 0

How to make sweave copy generated graphics to a subfolder?

时间秒杀一切 提交于 2019-12-10 18:25:18
问题 I would love to use some shell script based pdfcrop on all the graphics.pdf created from my Sweave report. Hence i'd be nice if all the graphics were stored to a subfolder instead of being dropped where all the latex stuff like .aux .log files (and so on) is located. If I just had to use the crop script on ALL files in a particular directory it would be much easier. Here's my Sweave chunk: \begin{figure}[htbp] \begin{center} <<fig=true,echo=false>>= print(mygraph) @ \caption{my graph} \end

Function to sanitize strings for LaTeX compilation?

时间秒杀一切 提交于 2019-12-10 16:13:00
问题 While xtable() has a sanitize.text.function argument which allows to sanitize strings with special charaters to stop LaTeX compilation from breaking in Sweave/knitr documents, the package does not export the function to the userspace. How can I sanitize strings like asdf_text outside of the xtable context, so as to have it transformed to something like asdf\_text ? (If possible I would prefer a small, self-contained solution.) 回答1: Unless I misunderstand your question, I think you've