为什么我无法使用knitr包中的kable函数打印正确的输出?

时间:2018-05-04 03:49:38

标签: r knitr kableextra

我一直在尝试使用kable函数打印数据字典。这是我的代码:

dict<-build_dict(my.data = tweets_train,linker=linker,option_description = NULL, prompt_varopts = T)
kable(dict,format="latex",caption="Data dictionary for the Training dataset") %>%
  kable_styling(position = "center")

这是输出:

> kable(dict,format="latex",caption="Data dictionary for the Training dataset") %>%
+   kable_styling(position = "center")

\begin{table}

\caption{\label{tab:}Data dictionary for the Training dataset}
\centering
\begin{tabular}[t]{l|l|l|l}
\hline
variable name & variable description & variable options & notes\\
\hline
sentiment & Sentiment Score 0 for Negative sentences and 4 for Positive sentences & 0 to 4 & The polarity of the tweet (0 = negative, 2 = neutral, 4 = positive)\\
\hline
text & The tweets collected & ''  oh u can take me to the game with u  mor  to zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz so tired   good night hokies & The dataset Sentiment 140 that originated from Stanford University for the purpose of Training\\
\hline
\end{tabular}
\end{table}

我该如何纠正这个问题。我第一次使用knitr,因为我必须创建一个数据字典。任何建议都将受到高度赞赏。提前谢谢。

1 个答案:

答案 0 :(得分:0)

这就是如@Marius

所提到的转移代码的方法

您需要将其放在降价文件中,如下所示:

Open markdown file

将其粘贴到r chunk

dict<-build_dict(my.data = tweets_train,linker=linker,
                 option_description = NULL, prompt_varopts = T)
knitr::kable(dict,format="latex",caption="Data dictionary for the Training dataset") %>%
knitr::kable_styling(position = "center")  

就像这样,把knitr放在kable之前调用库本身(或者在library(knitr)之前调用它):

enter image description here

然后保存并编织:) 希望有所帮助