使用R/knitr自动生成乳胶束载玻片

使用R/knitr自动生成乳胶束载玻片,r,latex,knitr,R,Latex,Knitr,我正在开发一个LaTeX报告模板,该模板自动生成beamer文档,从指定的目录中提取图形,并将它们放置在每张幻灯片上 下面是我在.Rnw文档中作为代码块使用的代码示例: <<results='asis',echo=FALSE>>= suppressPackageStartupMessages(library("Hmisc")) # get the plots from the common directory Barplots_dir<-"/home/figure

我正在开发一个LaTeX报告模板,该模板自动生成beamer文档,从指定的目录中提取图形,并将它们放置在每张幻灯片上

下面是我在.Rnw文档中作为代码块使用的代码示例:

<<results='asis',echo=FALSE>>=
suppressPackageStartupMessages(library("Hmisc"))

# get the plots from the common directory
Barplots_dir<-"/home/figure/barplots"
Barplots_files<-dir(Barplots_dir)

# create a beamer slide for each plot
# use R to output LaTeX markup into the document
for(i in 1:length(Barplots_files)){
  GroupingName<-gsub("_alignment_barplot.pdf", "", Barplots_files[i]) # strip this from the filename
    file <- paste0(Barplots_dir,"/",Barplots_files[i]) # path to the figure
    cat("\\subsubsection{", latexTranslate(GroupingName), "}\n", sep="") # don't forget you need double '\\' because one gets eaten by R !!
    cat("\\begin{frame}{", latexTranslate(GroupingName), " Alignment Stats}\n", sep="") 
    cat("\\includegraphics[width=0.9\\linewidth,height=0.9\\textheight,keepaspectratio]{", file, "}\n", sep="")
    cat("\\end{frame}\n\n") 
}  
@
=
SuppressPackageStatupMessages(库(“Hmisc”))
#从公共目录中获取绘图
Barplots\u dir
cat(“\\includegraphics{}”)
如果您来自旧的Swave世界(在那里可能需要打开图形设备、绘制绘图、关闭设备和
cat(\\includegraphics{}”)
)。只要你明白你在做什么。您的用例对我来说似乎非常合理,我没有更好的方法