【发布时间】:2015-07-10 18:43:59
【问题描述】:
在 R Sweave 文件 (.Rnw) 中,当我使用 knitr 编译 PDF 时,会出现不需要的 things 打印。很难准确解释发生了什么。我认为这是使用 data.table 包和 dplyr 包的结果,但我找不到任何其他示例。但是,我什至不确定我可以搜索什么。
这是问题的截图:
老实说,我真的不知道还能说什么,除了我想弄清楚如何摆脱它。如果有人认为这是一个简单的问题,而不仅仅是投反对票,您能否指出我在哪里做一些研究的正确方向?
\documentclass[11pt]{article}
\usepackage[sc]{mathpazo}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\geometry{verbose,tmargin=2cm,bmargin=2cm,lmargin=2cm,rmargin=2cm}
\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{2}
\setlength{\parindent}{0in}
\usepackage{url}
\usepackage[unicode=true,pdfusetitle,
bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=2,
breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=false]
{hyperref}
\hypersetup{
pdfstartview={XYZ null null 1}}
\usepackage{breakurl}
\usepackage{longtable}
\begin{document}
<<setup, include=FALSE, cache=FALSE>>=
library(knitr)
library(stringr)
library(RODBC)
library(plyr)
library(reshape2)
library(ggplot2)
library(grid)
library(data.table)
rw1 <- c("File1", "File1", "File1", "File2", "File2", "File2", "File3", "File3", "File3", "File1", "File1", "File1", "File2", "File2", "File2", "File3", "File3", "File3", "File1", "File1", "File1", "File2", "File2", "File2", "File3", "File3", "File3")
rw2 <- c("0.01", "0.01", "0.01", "0.01", "0.01", "0.01", "0.01", "0.01", "0.01", "0.02", "0.02", "0.02", "0.02", "0.02", "0.02", "0.02", "0.02", "0.02", "0.03", "0.03", "0.03", "0.03", "0.03", "0.03", "0.03", "0.03", "0.03")
rw3 <- c("Time", "Size", "Final", "Time", "Size", "Final", "Time", "Size", "Final", "Time", "Size", "Final", "Time", "Size", "Final", "Time", "Size", "Final", "Time", "Size", "Final", "Time", "Size", "Final", "Time", "Size", "Final")
rw4 <- c(123, 456, 789, 312, 645, 978, 741, 852, 963, 369, 258, 147, 753, 498, 951, 753, 915, 438, 978, 741, 852, 963, 369, 258, 147, 753, 498)
rw5 <- c("01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12", "01/01/12")
rw6 <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3)
rw7 <- c("Iteration", "Iteration", "Iteration", "Iteration", "Iteration", "Iteration", "Iteration", "Iteration", "Iteration", "Iteration", "Iteration", "Iteration", "Iteration", "Iteration", "Iteration", "Iteration", "Iteration", "Iteration", "Release", "Release", "Release", "Release", "Release", "Release", "Release", "Release", "Release")
rw8 <- c("None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "None", "Cannot Connect to Database", "None", "None", "None", "None", "None", "None", "None", "None")
Testdf = data.frame(rw1, rw2, rw3, rw4, rw5, rw6, rw7, rw8)
colnames(Testdf) <- c("FileName", "Version", "Category", "Value", "Date", "Number", "Build", "Error")
@
\title{Report}
\author{Current version}
\maketitle
\section{Report Summary}
This report documents the results
<<Benchmarks,echo=FALSE>>=
library(ggplot2)
# library(data.table)
library(dplyr)
versions<-unique(Testdf[order(Testdf$Number), ][,2])
# Testdf %<>%
# group_by(FileName) %>%
# mutate(Benchmark = Value[which(Category == "Time" & Number == min(Number))]) %>%
# ungroup()
setDT(Testdf)
Testdf[, Benchmark := Value[which.min(Number[Category == "Time"])], by = FileName]
Testdf$Version<-factor(Testdf$Version, levels = versions)
Testdf$Deviation<-Testdf$Value- Testdf$Benchmark
Testdf$DeviationP<-(Testdf$Value- Testdf$Benchmark)/Testdf$Benchmark
g<-ggplot(subset(Testdf, Category == 'Time') , aes(color = Value, x = Version, y = DeviationP, group = FileName)) +
geom_line(size=.25) + geom_point(aes(shape = Build), size = 1.5) +
scale_shape_manual(values=c(1,15)) + stat_summary(fun.y=sum, geom="line") +
ylab("Run Time Deviation from Benchmark (min)") +
scale_colour_gradient(name = 'Run Time (min)',low = 'blue', high = 'red') +
coord_cartesian(ylim=c(-105,105)) +
theme(axis.text.x = element_text(size = 10, angle = 90, vjust = .5)) + theme(axis.title.y = element_text(vjust = 1)) +
theme(axis.title.x = element_text(vjust = -0.1)) + theme(plot.margin=unit(c(0,0,0,0),"mm"))
g
@
\end{document}
【问题讨论】:
-
投反对票可能是因为您除了屏幕截图之外没有分享任何内容——没有代码。期望通常是 minimal reproducible 示例,您的示例两者都不是。你也没有展示任何你可能试图解决问题的东西。我从来没有真正使用过 Sweave,但是在 knitr 中有很多块选项可以很好地控制这类事情,我很确定 Sweave 在这方面是相似的。
-
@Gregor 原因是我很难创建一个可重现的示例。我正在进行编辑,但应该会解决这个问题。
-
这看起来不像 Sweave,它看起来像 knitr。如果是knitr,我可以回答。
-
knitr 一直给我带来麻烦。如果您能提供帮助,我将不胜感激。
-
请问您使用的是哪个版本的
data.table?
标签: r data.table knitr