sweave

Recommendations for developing Sweave documents

佐手、 提交于 2019-12-18 10:13:59
问题 I'm looking to streamline my Sweave document creation, and I'd like to hear about people's current setups. I feel like the holy grail goes something like this: Editing Rnw code on one half of the screen Single keybinding compiles Sweave document and runs pdflatex View PDF on the other half of the screen; once compiled, PDF is refreshed and centered around the portion of the document you're editing If compilation has errors, replace the PDF with the results of the compilation (e.g. latex

Attach date to PDF generated with Sweave

旧巷老猫 提交于 2019-12-13 16:19:39
问题 I generate via Sweave a daily report. I would like to attach to the PDF´s name the current date in the format YYYYMMDD. I am using the following code to generate the file: rnwfile <- system.file("Sweave", "Margin.Rnw", package = "utils") Sweave(rnwfile) tools::texi2pdf("Margin.tex") Margin.Rnw is my master copy of the report I want to generate (mixing LaTeX with R code). The output I get is a the file Margin.pdf . I would like instead to have a file named *Margin_YYYYMMDD.pdf*. I would

inline Latex code inside knitr R block

浪尽此生 提交于 2019-12-13 14:46:29
问题 I am looking for a way to put inline latex code into a R code chunk in Knitr. Here is my example code from the knitr example site : \documentclass{article} \begin{document} Example text outside R code here; we know the value of pi is \Sexpr{pi}. <<my-label, echo=FALSE, eval=TRUE>>= set.seed(1213) # for reproducibility x = cumsum(rnorm(100)) m <- mean(x) # mean of x print(m) cat(m) plot(x, type = 'l') # Brownian motion @ \textit{Mean is :} \textbf{\Sexpr{m}} \end{document} For something simple

Adding titles to xtable

守給你的承諾、 提交于 2019-12-13 13:24:46
问题 I'm not sure if this is an R question or a Sweave question. I"m looking at students' marks from 2 time points in a simple table (Grade 3 and Grade 6). I've created the table and it prints, however I want to add labels so people know which mark is from which Grade. My Sweave code is: <<MakeData,results='asis'>>= library(xtable) Grade3 <- c("A","B","B","A","B","C","C","D","A","B","C","C","C","D","B","B","D","C","C","D") Grade6 <- c("A","A","A","B","B","B","B","B","C","C","A","C","C","C","D","D"

RStudio will not write a .bbl file when compiling .Rnw file with citations in natbib

风流意气都作罢 提交于 2019-12-13 01:27:02
问题 I have a .Rnw file (Test.Rnw) in RStudio with citations. The .bib file is in the same folder as the .Rnw file, but when I compile the .Rnw file, no .bbl file is written out and I get the error: There were undefined citations And checking the log, I find, as expected: No file Test.bbl This is the code I'm trying to compile: \documentclass[12pt, oneside]{article} \usepackage{amsmath,amsfonts,amssymb} \usepackage{graphicx} \usepackage{float} \usepackage[sort,comma,numbers,super]{natbib}

xtable output for a list of tables

[亡魂溺海] 提交于 2019-12-12 18:55:11
问题 I've a list of tables and want to sweave it for LaTex output. Here is the code: Data <- esoph[ , 1:3] library(plyr) combos <- combn(ncol(Data),2) TabelFn <- function(x) { Table <- addmargins(table(Data[, x[1]], Data[, x[2]])) return(Table) } Table <- alply(.data=combos, .margins=2, .fun=TabelFn, .expand=TRUE) library(xtable) The list Table has three contingency tables in this case and I can sweave the output to LaTex using this code: << label = tabTable, echo = FALSE, results = tex >>= print

How to knit/Sweave to a different file name?

倖福魔咒の 提交于 2019-12-12 13:12:58
问题 By default, the knit/Sweave command will generate a tex file with the same name as the .Rnw file. I want to give it and the subsequent pdf file a different name is it possible? 回答1: In the header of an .Rmd file, you can specify a file name: --- title: "My title" output: pdf_document: pandoc_args: [ "--output=Custom_name.pdf" ] --- For .Rnw files you can directly call the function knitr::knit2pdf : knit2pdf(input.Rnw, output="Custom_name.pdf") 回答2: @mrub, knit2pdf(input.Rnw, output="Custom

Is there a way to push an R script file into a sweave document (opposite of tangle)

别等时光非礼了梦想. 提交于 2019-12-12 08:58:30
问题 I often create specific sweave files to do analyses and produce pdf documents, however, sometimes I want to take an existing R script file and run it while producing a pdf of the commands and output together. I know there is a tangle command that pulls the R commands out of an rnw sweave file to create an R script, but I want the opposite. Edit: I have considered creating a sweave file that just sources my R script, but I'd need to edit the sweave file each time, and it wouldn't deal very

How can I produce report quality tables from R?

喜你入骨 提交于 2019-12-12 08:15:13
问题 If I have the following dataframe called result > result Name CV LCB UCB 1 within 2.768443 1.869964 5.303702 2 between 4.733483 2.123816 18.551051 3 total 5.483625 3.590745 18.772389 > dput(result,"") structure(list(Name = structure(c("within", "between", "total" ), .rk.invalid.fields = list(), .Label = character(0)), CV = c(2.768443, 4.733483, 5.483625), LCB = c(1.869964, 2.123816, 3.590745), UCB = c(5.303702, 18.551051, 18.772389)), .Names = c("Name", "CV", "LCB", "UCB" ), row.names = c(NA,

Error compiling Rnw to tex

浪尽此生 提交于 2019-12-12 05:19:51
问题 I had a problem using function Sweave . It seemed to be an encoding problem because I did not specify any encoding like: \usepackage[latin1]{inputenc}. Now using button "Compile PDF" works -> PDF is generated and everythink is OK. But I'm getting 30 warnings and 18 badboxes. Using function Sweave to generate first the tex file fails with this message: Error: chunk 4 (label = t4) Error in file(con, "w") : cannot open the connection In addition: There were 31 warnings (use warnings() to see