我是R的新手并且一直试图在R markdown中编写我的项目报告。但是我遇到了问题。我尝试在堆栈溢出以及其他网站上实现解决方案,但我无法取得进展。
详细说明:
R version 3.2.1(2015-06-18) - “世界着名的宇航员”
RStudio版本0.99.441 - ©2009-2015
Mac OS X Yosemite版本10.10.5
已安装pandoc 1.15.0.6 https://github.com/jgm/pandoc/releases/tag/1.15.0.6
来自http://tug.org/mactex/的MacTeX-2015分发
MacTEX都-20150613
在Global选项下,我使用knitr编织Rnw文件,使用XeLaTex将Typeset LaTeX编织成PDF,在编译后取消选择干净的辅助输出。
我收到以下错误:
输出文件:07.Random_Forest.knit.md
/ usr / local / bin / pandoc 07.Random_Forest.utf8.md - 来自markdown + autolink_bare_uris + ascii_identifiers + tex_math_single_backslash-implicit_figures --output 07.Random_Forest.pdf --template / Library / Frameworks / R.framework / Versions / 3.2 / Resources / library / rmarkdown / rmd / latex / default-1.14.tex --highlight-style tango --latex-engine / Library / TeX / texbin / pdflatex !未定义的控制序列。 l.921 {\ centering \ includegraphics
pandoc:从TeX源生成PDF时出错 错误:pandoc文档转换失败,错误43 执行暂停
附上我的R降价代码的一部分以供参考:
---
title: "Decision Trees and Random Forest"
paper: a4paper
fontsize: 12pt
geometry:
- tmargin=2cm
- bmargin=2cm
- lmargin=3cm
- rmargin=3cm
documentclass: report
classoption: twoside, bindingoffset=1cm
linkcolor: blue
author: "Chaitanya Jagtap"
date: "15 September 2015"
output: pdf_document
---
opts_chunk$set(echo=FALSE, warning=FALSE, message=FALSE, error=FALSE, collapse=TRUE, tidy=TRUE, highlight=TRUE, comment='')
opts_knit$set(progress=TRUE, verbose=TRUE)
```{r include=TRUE}
library(extrafont)
loadfonts()
library(SDMTools)
library(caTools)
library(randomForest)
library(rpart)
library(rattle)
library(rpart.plot)
library(RColorBrewer)
library(partykit)
library(rmarkdown)
library(geometry)
library(knitr)
library(highr)
library(xtable)
set.seed(211)
fonttable()
options(digits=4)
par(cex=0.9,cex.axis=1,cex.lab=1,cex.main=1.2,cex.sub=1,
font=1,font.axis=1,font.lab=2,font.main=2,font.sub=1,
pin=c(4,3), mai=c(1, 1, 1, .2), oma=c(0.2,0.2,2,0.2), mgp = c(3, 1, 0), adj=0.5,
las=0, xaxs="i", yaxs="i",
col.lab = "firebrick4", col.main="deepskyblue4", col.sub="royalblue", lab=c(10,10,7),
lwd=2,family="Times New Roman", ps=12)
setwd("/Users/Urmila/Desktop/Chaitanya/Study/001_Great Lakes/001_Capstone/002_Give_me_some_credit/")
load("capstone_df_train.RData")
load("capstone_df_test.RData")
xyvar <- c( "GB", "Age_woe", "num_30_59_dpd_woe", "num_60_89_dpd_woe", "num_90_dpd_woe",
"num_open_trades_woe", "num_RE_trades_woe", "Rev_Util_unsec_woe", "Debt_Ratio_woe",
"MI_num_depend_woe")
xvar <- c("Age_woe", "num_30_59_dpd_woe", "num_60_89_dpd_woe", "num_90_dpd_woe",
"num_open_trades_woe", "num_RE_trades_woe", "Rev_Util_unsec_woe", "Debt_Ratio_woe",
"MI_num_depend_woe")
capstone_df_train_xyvar <- capstone_df_train[xyvar]
capstone_df_test_xyvar <- capstone_df_test[xyvar]
weight <- ifelse(capstone_df_train_xyvar$GB == 0,1,12)
dtree_train <- rpart(GB ~ ., data=capstone_df_train_xyvar,
method="class", parms=list(split="information"),
minsplit = 1000, minbucket = 500, cp=-1,
weights = weight)
```
```{r include = TRUE}
dtree_train$cptable
```
```{r include=TRUE, fig.align='center', fig.cap="Plot of cross-validated error against complexity parameter cp"}
plotcp(dtree_train, minline = TRUE, lty=2, col = "firebrick", upper = "size")
mtext("Plot of cross-validated error against complexity parameter cp", side=3, cex=1.1,
line=0.6, col = "dodgerblue4", outer=TRUE)
box("plot", col="blue", lty = "solid")
box("figure", col="forestgreen", lty = "solid")
```
感谢您的时间和帮助。
切塔尼亚
答案 0 :(得分:1)
Pandoc不知道您的输出包含图形,因为您使用了块选项fig.align = 'center'
。您可以将graphics: yes
添加到R Markdown文档的YAML元数据中。