当我运行我的 r-markdown 代码来生成 PDF 时,有文本代替了图像。运行块并在“figure”文件夹中生成 pdf 图像,但图像应该在 PDF 中的位置是 text figure/unnamed-chunk-12.pdf
。
我以前从未有过这种情况,并且已经成功地生成了许多带有图像的 pdf 文件。似乎是在spin(file, format = 'Rmd', report=F)
运行时,![plot of chunk unnamed-chunk-12]
和括号没有放在 md 文件中。
任何想法为什么会这样以及我如何纠正它?
例子:
#' ---
#' title: "Testing the figure generation from 'spin'"
#' ---
#' ****
#+ echo=FALSE, eval = FALSE
require(knitr)
require(rmarkdown)
#+
#' # Background
#' For some reason the plots don't show - they are missing text in the md file.
#'
#+ echo=FALSE, message = FALSE, warning = FALSE
plot(rnorm(100), rnorm(100))
#+
#' But the text still works.
#'
#+ eval=FALSE, include = F
file = "~/Desktop/TestSpinFigs.R" # THIS FILE
setwd(dirname(file)); # Set the directory to be where the file is
spin(file, format = 'Rmd', report=F) # Make a Markdown version
render(paste(substring(file,0,(nchar(file)-1)),"md",sep=""), pdf_document(toc = TRUE, toc_depth=6, number_sections= TRUE),
output_file = paste(substring(file,0,(nchar(file)-2)),".pdf",sep="")) # Create the PDF
#+