knitr使用表格代码而不是乳胶文档中的表格生成##

时间:2014-02-21 00:57:12

标签: r latex knitr rstudio xtable

在RStudio中使用Knitr创建LaTeX文档时,输出在PDF结果中带有##,如:

 ## % latex table generated in R 3.0.2 by xtable 1.7-1 package
 ## % Thu Feb 20 21:49:34 2014
 ## \begin{table}[ht]

我尝试了一些选项:

 <<results='asis'>>=

但是编译器无法创建PDF。

任何线索?

我的SessionInfo是:

sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=Portuguese_Brazil.1252  LC_CTYPE=Portuguese_Brazil.1252   
[3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C                      
[5] LC_TIME=Portuguese_Brazil.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] xtable_1.7-1    lattice_0.20-24

loaded via a namespace (and not attached):
[1] evaluate_0.5.1 formatR_0.10   grid_3.0.2     knitr_1.5.22   stringr_0.6.2  tools_3.0.2 

代码块:

<<>>=

library(xtable)  

Frequencia <- c(3,2,3,4,5,11,14,14,4)  
Soma <- sum(Frequencia)  

dist.freq <- data.frame(
  Intervalo <-   c("10-19","20-29","30-39","40-49","50-59","60-69","70-79","80-89","90-99"),
  Ponto.Medio <- c(14.5,    24.5,   34.5,   44.5,   54.5,   64.5,   74.5,   84.5,   94.5),
  Frequencia,
  Frequencia.Relativa <- Frequencia / Soma  
  )

x <- xtable(dist.freq)

print(x)
@

1 个答案:

答案 0 :(得分:0)

```{r TableName, results='asis', echo = FALSE, message = FALSE} 

library(xtable)
Frequencia <- c(3,2,3,4,5,11,14,14,4)  
Soma <- sum(Frequencia)  

dist.freq <- data.frame(
  Intervalo <-   c("10-19","20-29","30-39","40-49","50-59","60-    69","70-79","80-89","90-99"),
  Ponto.Medio <- c(14.5,    24.5,   34.5,   44.5,   54.5,   64.5,       74.5,   84.5,   94.5),
  Frequencia,
  Frequencia.Relativa <- Frequencia / Soma  
  )

print(xtable(dist.freq,caption = "Your caption"), comment=FALSE)
```