Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试使用knitr导出为pdf,需要很长时间才能完成_R_Knitr - Fatal编程技术网

尝试使用knitr导出为pdf,需要很长时间才能完成

尝试使用knitr导出为pdf,需要很长时间才能完成,r,knitr,R,Knitr,我有这个数据框。它是我实际数据帧的一个很小的子集,但列名称与其他所有内容相同: 这是包含以下数据的数据帧: dput(p) structure(list(Hostname = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("server101", "server102", "server103", "server104", "test101", "app101d", "web25", "web26", "web111", "web11",

我有这个数据框。它是我实际数据帧的一个很小的子集,但列名称与其他所有内容相同:

这是包含以下数据的数据帧:

dput(p)

structure(list(Hostname = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("server101", 
"server102", "server103", "server104", "test101", "app101d", 
"web25", "web26", "web111", "web11", "web123", "tomcat101", "tomcat103", 
"tomcat104"), class = "factor"), Date = structure(c(1441373431, 
1441372531, 1441737938, 1441337431, 1441374331, 1441367131), class = c("POSIXct", 
"POSIXt"), tzone = ""), Cpubusy = c(22, 21, 20, 28, 22, 20), 
    UsedPercentMemory = c(3L, 3L, 21L, 3L, 3L, 4L), App = structure(c(1L, 
    1L, 1L, 1L, 1L, 1L), .Label = c("WEB", "DB"), class = "factor"), 
    HA = structure(c(1L, 1L, 1L, 1L, 1L, 1L), .Label = c("server3456", 
    "backup101", "ha123", "No HA Host", "No HA Host", "server120", 
    "server234", "server666", "No HA Host"), class = "factor"), 
    DR = structure(c(5L, 5L, 5L, 5L, 5L, 5L), .Label = c("Cannot login to DR Host", 
    "dr101", "dr345", "dr444", "dr5678", "No DR Host", "drserver11", 
    "dr666", "No HA Host", "No HA Host", "No HA Host"), class = "factor")), .Names = c("Hostname", 
"Date", "Cpubusy", "UsedPercentMemory", "App", "HA", "DR"), row.names = c(NA, 
6L), class = "data.frame")
这是我的应用服务器映射数据框:

dput(c)
structure(list(App = structure(c(1L, 2L, 2L, 2L, 2L, 1L), .Label = c("WEB", 
"APP"), class = "factor"), Prod = structure(c(1L, 5L, 6L, 4L, 
3L, 2L), .Label = c("server101", "server102", "server104", "server106", 
"server107", "server109"), class = "factor"), HA = structure(c(1L, 
3L, 3L, 3L, 3L, 2L), .Label = c("server3456", "server3456", "No HA Host"
), class = "factor"), DR = structure(c(1L, 2L, 2L, 2L, 2L, 3L
), .Label = c("dr5678", "No DR Host", "No DR Host"), class = "factor")), .Names = c("App", 
"Prod", "HA", "DR"), row.names = c(NA, 6L), class = "data.frame")
这只是数据的一小部分。我正在尝试运行knitr将我的分析导出为pdf文件,如下所示:

application<-unique(c$App, drop=TRUE)
application<-droplevels(application)

metrics<-unique(colnames(pp[,c(3:4)]))
env<-unique(colnames(c[,c(2:4)]))

applicationgplot通常非常慢在控制台上运行时有多慢?当我通过控制台运行时,速度肯定更快。我很好奇是否有一些语法问题?有什么办法可以优化这个吗?
```{r qplot,fig.width=10, fig.height=8, message=FALSE, results = 'asis', echo=FALSE, warning=FALSE, fig.cap="long caption", fig.scap="short"}


library(ggplot2)
library(knitr)



for (product in application){ 
  product<-gsub("\\(", "_",product)
  product<-gsub("\\)", "_",product)
  for(en in env){

     tryCatch({
        mergedData <- merge(pp, c, by.x=c("Hostname"),by.y=en)
        cat(paste(product, en, " - Environment"))
        cat("\n")

        for(m in metrics){

            p<-ggplot(mergedData,aes(Date, m, group=Hostname, colour=Hostname))+geom_line()+
              geom_smooth(method="lm", se=T, colour="blue")+
              facet_wrap(~Hostname)+theme_bw()+
              ggtitle(m)+
              theme(strip.background = element_rect(colour="blue", fill="#b2d8ff"),axis.text.x = element_text(angle = 30,hjust = 1),plot.background = element_rect(size = 1, colour="black",linetype = "solid"))+
              scale_fill_brewer(palette="RdYlGn")
              print(p)
              cat("\n")
       }
     },error=function(e) {
        print(paste(product, "does not have - ", en, "- Environment"))
       print("\n")
     })

  }

}

```