sweave

Recommendations for developing Sweave documents

五迷三道 提交于 2019-11-29 19:55:06
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 errors or Sweave errors) I am guessing/hoping that the solution is part Emacs/ESS combined with some code

Error when compiling pdf using knitr in rstudio

落花浮王杯 提交于 2019-11-29 18:35:11
问题 I have installed the packages Sweave as well as knitr on both Linux mint and Windows 7, and it works well on Windows, but fails when using rstudio in Linux . After installing the pkgs, I write a simple dw.Rnw as follows: \documentclass{article} \begin{document} The regression model is as follows <<echo=TRUE>>= pop=read.table("pop.txt",header=TRUE) attach(pop) lm.sol=lm(y~year) summary(lm.sol) @ \end{document} When I press the button ' Compile PDF ' in rstudio, it returns the following error

Get Emacs to ignore contents of \Sexpr{} command in Sweave document to prevent incorrect $-based syntax highlighting

萝らか妹 提交于 2019-11-29 17:29:55
问题 When editing an Sweave document in LaTeX (using the Noweb mode), Emacs knows to "ignore" code that is in <<>>= blocks. However, for interstitial \Sexpr{} blocks, this isn't the case. Given that R references by columns via '$' and LaTeX uses $ to set-off equations, these \Sexpr{} blocks often break the syntax highlighting, like so: I have a very rudimentary understanding the elisp & Emacs syntax highlighting, but my hope is that it might be possible to add something to .emacs that will disable

Way to automatically escape characters ('_','\' etc) using knitr

ぃ、小莉子 提交于 2019-11-29 15:35:20
问题 I m using Rstudio under Win7. Is there a way that knitr automatically escape a character? Please see below for a simpler example: \documentclass[a4]{article} \title{Example} \author{Stat-R} \begin{document} \maketitle <<nothing,echo=FALSE>>= my_name <- 'hari' my_number <- 100 df1 <- data.frame(my_name,my_number) df1 # names(df1) @ \section{Testing only} Now I will print the columnnames of my data frame df1 $\Sexpr{names(df1)}$ \end{document} I get the following output... But I want the

Sweave syntax highlighting in output

↘锁芯ラ 提交于 2019-11-29 15:33:56
问题 Has anyone managed to get color syntax-highlighting working in the output of Sweave documents? I've been able to customize the output style by adding boxes, etc. in the Sweave.sty file as follows: \DefineVerbatimEnvironment{Sinput}{Verbatim}{fontseries=bc,frame=single} \DefineVerbatimEnvironment{Soutput}{Verbatim}{frame=leftline} \DefineVerbatimEnvironment{Scode}{Verbatim}{fontseries=bc} And I can get the minted package to do syntax highlighting of verbatim-code blocks in my document like so:

Combining several regression tables into one for use in xtable with Sweave in R

狂风中的少年 提交于 2019-11-29 03:00:52
问题 xtable in Sweave works awesome, but does one table per regression. You can feed it a data frame, too, so I have been manually rbind ing and paste ing results into data frames, but that doesn't seem very scalable. Is there a more automated/robust solution that works like xtable , but on multiple lm objects? Are all of the tables that I see in papers/books generated manually? Is there a better solution to my janky code that generates a data frame to feed to xtable ? library(reshape2) data <-

Using xtable with R and Latex, math mode in column names?

风流意气都作罢 提交于 2019-11-29 02:35:24
问题 I'm using xtable to compile tables from R automatically while compiling my TeX document. The question I have is how I get the variable names in the table (which in my case are the column names in a dataframe) to be in math mode. I have stored my results in the dataframe adf.results, and essentially what I want is colnames(adf.results) <- c(" ", "$m^r_t$", "$\delta p_t$", "$R^r_t$", "$R^b_t$", "$y^r_t$") but that simply inserts $m^r_t$ ... as the column names without interpreting them as being

Handling Latex backslashes in xtable

寵の児 提交于 2019-11-28 22:43:39
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 print.xtable , but it is not obvious to me how to use this, and ?print.xtable provides no examples.

Counts & Percentages in xTable, Sweave, R, cross tabulations

我的梦境 提交于 2019-11-28 19:18:11
问题 Edit: Building off of aL3xa's answer below, I've modified his syntax below. Not perfect, but getting closer. I still haven't found a way to make xtable accept \multicolumn{} arguments for columns or rows. It also appears that Hmisc handles some of these type of tasks behind the scenes, but it looks like a bit of an undertaking to understand what's going on there. Does anyone have experience with the latex function in Hmisc? ctab <- function(tab, dec = 2, margin = NULL) { tab <- as.table(tab)

What is the knitr equivalent of `R CMD Sweave myfile.rnw`?

倾然丶 夕夏残阳落幕 提交于 2019-11-28 15:34:34
What is the command-line knitr equivalent of R CMD Sweave myfile.rnw ? Maiasaura The general solution (works regardless of the R version): Rscript -e "library(knitr); knit('myfile.Rmd')" Since R 3.1.0, R CMD Sweave has started to support non-Sweave documents (although the command name sounds a little odd), and the only thing you need to do is to specify a vignette engine in your document, e.g. %\VignetteEngine{knitr::knitr} To see the possible vignette engines in knitr , use library(knitr) library(tools) names(vignetteEngine(package = 'knitr')) # "knitr::rmarkdown" "knitr::knitr" "knitr::docco