sweave

Sweave doesn't seem to get .Rnw file encoding right

两盒软妹~` 提交于 2019-11-28 08:57:28
问题 This question arose out of the following question on tex.sx: Sweave generating invalid LaTeX. The problem seems to be that Sweave is not recognizing the encoding of the file, despite the locale being set to UTF-8, and the .Rnw file being saved as UTF-8. The end result is that any .Rnw file that contains non-ASCII characters ends up producing NA in the resultant .tex file. As you can read in the comments to that question, another user doesn't show the problem, with what is apparently an

get filename and path of `source`d file

偶尔善良 提交于 2019-11-28 05:27:18
How can a source d or Sweave d file find out its own path? Background: I work a lot with .R scripts or .Rnw files. My projects are organized in a directory structure, but the path of the project's base directory frequently varies between different computers (e.g. because I just do parts of data analysis for someone else, and their directory structure is different from mine: I have projects base directories ~/Projects/StudentName/ or ~/Projects/Studentname/Projectname and most students who have just their one Project usually have it under ~/Measurements/ or ~/DataAnalysis/ or something the like

How to avoid using round() in every \\Sexpr{}?

佐手、 提交于 2019-11-28 04:22:45
Is there a way to avoid the function round() when using Sweave/knitr? It's really annoying to write round(,2) in every \Sexpr{} . I would like to have two decimal places through the whole document. Thanks for your help Macs If you have read the motivation of the knitr package , you probably know I'm the person who hates round() inside \Sexpr{} most. I suggested this to R core long time ago for Sweave but it was ignored, so I started my own package. Although the answer by Josh O'Brien is absolutely correct, I should say you really only need options(digits = 2) with knitr , and there is no need

General guide for creating publication quality tables using R, Sweave, and LaTeX

强颜欢笑 提交于 2019-11-28 02:34:21
There are a range of tools available for creating publication quality tables using R, Sweave, and LaTeX. In particular, there are helper functions like latex in the Hmisc package, and xtable in the xtable package. I've also often written my own code so that I could have complete control over table formatting (e.g., see this example ). However, when preparing publication quality tables a range of issues often arise: how and when to apply numeric formatting how to precisely control alignment of columns and cells how to precisely control cell borders how to convert variable labels to variable

Handling Latex backslashes in xtable

我的未来我决定 提交于 2019-11-27 14:26:01
问题 I have a table that includes the following column: mytable <- data.frame(beta_0 = c(1,2,3) What I want to do is output a table with a column header in latex markup, e.g. $\beta_0$ However, I can not seem to figure out how to output the "$\beta_0$" using print.xtable : colnames(mytable) <- "$\beta_0$" library(xtable) print(xtable(mytable), include.rownames = F) returns a column header of \eta\_0\$ instead of $\beta_0$ I presume that the answer is the "sanitize.colnames.function" argument to

Putting line number for R code with knitr

回眸只為那壹抹淺笑 提交于 2019-11-27 14:05:41
I wonder if there is any function to put line numbers with knitr in .Rnw . I found this discussion and some documents (now removed from the web) but could not find the way to put line numbers. This solution uses the LaTeX listings package to create line numbers. I can only get them to work by accumulating across all code chunks, but I imagine there is a similar solution that will enumerate lines only within each chunk. Here's the .Rnw source: \documentclass{article} \usepackage{listings} \begin{document} <<setup, echo=FALSE>>= knit_hooks$set(source = function(x, options) { paste("\\begin

Run Sweave or knitr with objects from existing R session

谁都会走 提交于 2019-11-27 07:09:00
Suppose I have an object x in my current session: x <- 1 How can I use this object in an Sweave or knitr document, without having to assign it explicitly: \documentclass{article} \begin{document} <<>>= print(x) @ \end{document} Reason I am asking is because I want to write an R script that imports data and then produces a report for each subject using an Sweave template. I think it just works. If your Sweave file is named "temp.Rnw", just run > x <- 5 > Sweave("temp.Rnw") You'll have to worry about naming the resulting output properly so each report doesn't get overwritten. I would take a

get filename and path of `source`d file

て烟熏妆下的殇ゞ 提交于 2019-11-27 05:33:41
问题 How can a source d or Sweave d file find out its own path? Background: I work a lot with .R scripts or .Rnw files. My projects are organized in a directory structure, but the path of the project's base directory frequently varies between different computers (e.g. because I just do parts of data analysis for someone else, and their directory structure is different from mine: I have projects base directories ~/Projects/StudentName/ or ~/Projects/Studentname/Projectname and most students who

Can Sweave produce many pdfs automatically?

天大地大妈咪最大 提交于 2019-11-27 03:28:20
I analyze measurements from many cities (hundreds), and need to create separate reports per city (in Adobe pdf-format). My process is like this: First RStudio to prepare the data to be shown, saved in X.Rda. In X.Rnw (RStudio) I read X.Rda, select one city, and produce the tables and plots. In RStudio I press "Compile PDF" and the city-report X.pdf is produced. I go to step 2, choose another city, and so on. This is very tedious, and looks perfect for a for-loop per city, but how can it be done? Thank you r-contributors! /Chris Yihui Xie You can use something like a for loop with a global

R, Sweave, LaTeX - escape variables to be printed in LaTeX?

◇◆丶佛笑我妖孽 提交于 2019-11-27 02:51:26
问题 I've been searching for the past 2 days, and while I've found similar questions on Stack Overflow and other discussions on Google, I've found nothing matching my request. I have a pre-existing application that I'm supporting, which is built around R. Sweave Rnw template files are used to generate .tex files, which are used to generate .pdf files. Within the Rnw, there is existing code such as this: \begin{tabular}{lll} & {\bf \textcolor{TitlesColor}{Report name:}} & \Sexpr{print(myReport