sweave

Print the sourced R file to an appendix using Sweave

余生长醉 提交于 2019-11-30 16:21:29
I keep R and Rnw files separate, then load the R data/plots with load("file.R") in the first Sweave chunk. Is there a way that I can print the sourced R file to an appendix without executing all of the code? (i.e., the code is slow enough that I don't want to source() it in an echo=TRUE chunk). Thanks! Update -- actually, I don't think my source() idea works. How about using a Latex package? Add into your header \usepackage{fancyvrb} Then \VerbatimInput{yourRfile.R} You can use highlight package to output nicely formatted, colorful code: highlight("myRfile.R", renderer = renderer_latex

Sweave, include sourced R-Function files

守給你的承諾、 提交于 2019-11-30 15:40:12
I have an Rjob writen in file a.R which calls functions writen in file b.R, and a snw file c.snw. I call c.snw via "R CMD c.snw". I am looking for a possibilty to only include a.R via \SweaveInput{a.R} into c.snw, but the code of the functions called from a.R should also be written in the tex file. This implies that Sweave traces all source() commands in the included main R file (here a.R). Can anyone suggest how to do this? I guess life will be easier with the knitr package in this case. You can read a.R as a chunk label-a , and write it in c.Rnw : <<read-code>>= read_chunk('a.R', labels =

Changing the font size of table using print.xtable

↘锁芯ラ 提交于 2019-11-30 15:29:59
问题 I want to change the font size of the table using print.xtable. Using print(xT, size="\\tiny") works but I don't know other options for size. Something like size="7pt" would be nice. 回答1: You may choose a particular font size with the \fontsize{<size>}{<line space>} command: print(xt, size="\\fontsize{9pt}{10pt}\\selectfont") 来源: https://stackoverflow.com/questions/33994194/changing-the-font-size-of-table-using-print-xtable

Changing the font size of table using print.xtable

喜欢而已 提交于 2019-11-30 14:54:24
I want to change the font size of the table using print.xtable. Using print(xT, size="\\tiny") works but I don't know other options for size. Something like size="7pt" would be nice. You may choose a particular font size with the \fontsize{<size>}{<line space>} command: print(xt, size="\\fontsize{9pt}{10pt}\\selectfont") 来源: https://stackoverflow.com/questions/33994194/changing-the-font-size-of-table-using-print-xtable

Error when compiling pdf using knitr in rstudio

倖福魔咒の 提交于 2019-11-30 13:08:16
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 messages: During startup - Warning messages: 1: Setting LC_CTYPE failed, using "C" 2: Setting LC_COLLATE

Print the sourced R file to an appendix using Sweave

拟墨画扇 提交于 2019-11-30 07:50:44
问题 I keep R and Rnw files separate, then load the R data/plots with load("file.R") in the first Sweave chunk. Is there a way that I can print the sourced R file to an appendix without executing all of the code? (i.e., the code is slow enough that I don't want to source() it in an echo=TRUE chunk). Thanks! Update -- actually, I don't think my source() idea works. 回答1: How about using a Latex package? Add into your header \usepackage{fancyvrb} Then \VerbatimInput{yourRfile.R} 回答2: You can use

R / Sweave arguments

 ̄綄美尐妖づ 提交于 2019-11-30 05:28:29
问题 I'm using R and Sweave to generate a report. R CMD Sweave MyReport.Rnw I want to be able to send arguments to the R code because the report is , of course, "Dynamic" .So, I would like to be able to do something like this: R CMD SWeave MyReport.Rnw PatientId=5 ...and have the R code read the PatientId value in a variable... How do I do this? Somebody mentioned using environment variables but that's seems like a non-elegant solution. 回答1: To get arguments passed from R command line, you can use

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

我的梦境 提交于 2019-11-30 05:10:13
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 <- data.frame(matrix(rnorm(50), 10, 5)) names(data) <- letters[1:5] l.raw <- list() l.raw[["a"]] <- lm(a ~ d

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

孤者浪人 提交于 2019-11-30 04:54:52
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 in math mode. Does anyone have a solution? as suggested in the xtable gallery vignette you should use

Displaying errors with sweave

你。 提交于 2019-11-30 03:38:38
问题 I'm writing some R notes with Sweave and would like to show common errors. For example, <<echo=TRUE, eval=TRUE>>= x = 5 #Case matters! x*X @ However when sweaving, the document won't compile due to the R error. Is there any way to make sweave compile and show the (nicely formated) error? 回答1: As Shane suggests, use <<echo=TRUE,eval=FALSE>> for the code that will error, but you want to display, and then again with <<echo=FALSE,eval=TRUE,results=verbatim>> but with the same code wrapped in a