Hi, I have what I think should be a basic question on knitr. I am just moving to knitr, and previously I had created functions which automatically created latex wrappers for many (100s) figures. I also have other functions which automatically create pages worth of latex tables. The knitr method seems to be to write this figure code by hand. Is there a way to use my pre-existing functions to output latex into the .Rnw document? So far, everything I've tried isn't doing it. (I've been modifying the functions to output big strings of latex instead of writing files, and trying various methods to print that output into the .Rnw file). It feels like this should be easy... the output of the R-block is latex. thanks, Daryl
I think in most cases you are probably on the wrong track if you have to generate LaTeX code for figures from R code (LaTeX tables are another story), but your case might be different. You did not give a specific example on why you had to do that, so I cannot give any advice for now. My best guess is <<results='asis'>>whatever_your_figure_functions_are() @ So please provide a minimal example, and avoid indefinite descriptions like "seems" or "feels like" (in particular, "this should be easy" made me feel my IQ suddenly dropped by 50%). Regards, Yihui -- Yihui Xie <xieyihui at gmail.com> Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Wed, Oct 9, 2013 at 10:36 PM, Daryl Morris <darylm at uw.edu> wrote:> Hi, > > I have what I think should be a basic question on knitr. I am just moving > to knitr, and previously I had created functions which automatically created > latex wrappers for many (100s) figures. I also have other functions which > automatically create pages worth of latex tables. > > The knitr method seems to be to write this figure code by hand. > > Is there a way to use my pre-existing functions to output latex into the > .Rnw document? So far, everything I've tried isn't doing it. (I've been > modifying the functions to output big strings of latex instead of writing > files, and trying various methods to print that output into the .Rnw file). > > It feels like this should be easy... the output of the R-block is latex. > > > thanks, Daryl > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Daryl Morris
2014-Feb-27 22:58 UTC
[R] expressions (nesting, substitution, 2-stage evaluation)
Hi, I have a function which generates many plots. To keep it simple, let's say I want to set the main title based on where we are in nested loops. So, something like vectorA = c("a","b","c") vectorB = c("a","b","c") for(ii in vectorA) { for(jj in vectorB) { plot(0:1,0:1) title(main = paste(ii,jj)) } that part is easy! The question is what if I wanted vectorA to be an expression? I'd like to be able to set vectorA = c(expression(paste("TNF-",alpha)),expression(paste("IFN-",gamma))), and have the plot title show the greek letters. Obviously, in the for-loop I could build the expression all at once, but there are lots of programmatic reasons I'd like to be able to have this program structure. Is there a solution which modifies either/both (1) the setting of main in the loop (2) how I define the vector outside of the loop? thanks, Daryl