Reputation: 3656
I have a small problem with the kable
command from package knitr
in combination with data.table
.
Previously, I could print data.table
s in markdown with kable
, but now there is an error message. The solution now is to convert to data.frame
, but this is cumbersome.
library(data.table)
library(knitr)
kable(mtcars) # works
mtcars = data.table(mtcars, keep.rownames = T)
kable(mtcars)
Error in `[<-.data.table`(`*tmp*`, , isn, value = c("FALSE", "TRUE", "TRUE", :
j must be vector of column name or positions
In addition: Warning message:
In `[<-.data.table`(`*tmp*`, , j, value = 1) :
Coerced 'double' RHS to 'character' to match the column's type; may have truncated precision. Either change the target column to 'double' first (by creating a new 'double' vector length 32 (nrows of entire table) and assign that; i.e. 'replace' column), or coerce RHS to 'character' (e.g. 1L, NA_[real|integer]_, as.*, etc) to make your intent clear and for speed. Or, set the column type correctly up front when you create the table and stick to it, please.
SessionInfo:
R version 3.1.0 (2014-04-10)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8
[6] LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=en_US.UTF-8 LC_ADDRESS=en_US.UTF-8 LC_TELEPHONE=en_US.UTF-8
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=en_US.UTF-8
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] rCharts_0.4.2 plyr_1.8.1 googleVis_0.5.3 shiny_0.10.0 scagnostics_0.2-4 rJava_0.9-6
[7] ggvis_0.3.0.9001 knitr_1.6 FSelector_0.19 randomForest_4.6-7 RWeka_0.4-21 rpart.plot_1.4-4
[13] rpart_4.1-8 stringdist_0.7.3 PerformanceAnalytics_1.1.0 xts_0.9-7 scales_0.2.3 gdata_2.13.2
[19] stringr_0.6.2 freqparcoord_1.0.0 mvtnorm_0.9-9997 FNN_1.1 GGally_0.4.6 treemap_2.1-1
[25] tabplot_1.1 ffbase_0.11.3 ff_2.2-13 bit_1.1-12 ggplot2_1.0.0 reshape2_1.4
[31] lubridate_1.3.3 zoo_1.7-10 data.table_1.9.3
Upvotes: 1
Views: 795
Reputation: 506
Here is he solution, you need to make sure all vectors' format inside data.frame prior to apply kable knitr::kable()
Upvotes: 1