r - Unexpected xtable output (in html) when formatting numbers -


in following code, when enable prettynum(formatc... command, strange output see in picture. code worked ok r 3.1.1. there no problem when output format pdf.

--- title: "untitled" output: html_document ---  create test data.  ```{r} library(xtable)  my_tab <- structure(list(category = c("categ 1", "categ 1", "categ 1",  "categ 1", "categ 1", "categ 2", "categ 3", "categ 3", "categ 4",  "categ 4"), customer = c("512", "541", "579", "635",  "705", "726", "o33", "o54", "10004", "10012"), ammount = c(192.65,  1046.62, 5053.74, 10950.59, 101.89, 48.99, 2.56, 1.62, 728.63,  846.7)), row.names = c(na, 10l), class = "data.frame")  # my_tab[,3] <-  prettynum(formatc(my_tab[,3], format='f', digits=2), big.mark = ".", decimal.mark = ",")  ```  print table:  ```{r, results='asis', echo=false}  print(xtable(my_tab , align="ll|rr",digits=2), type="html", include.rownames = false,                 html.table.attributes='class="table table-striped table-hover"') ``` 

enter image description here

r version 3.2.0 (2015-04-16) platform: i386-w64-mingw32/i386 (32-bit) running under: windows 7 x64 (build 7601) service pack 1  locale: [1] lc_collate=greek_greece.1253  lc_ctype=greek_greece.1253    lc_monetary=greek_greece.1253 lc_numeric=c                  lc_time=greek_greece.1253      attached base packages: [1] stats     graphics  grdevices utils     datasets  methods   base     other attached packages: [1] xtable_1.7-4    loaded via namespace (and not attached): [1] htmltools_0.2.6 tools_3.2.0     yaml_2.1.13     rmarkdown_0.7   digest_0.6.8 

i think xtable has problems leading whitespace.

you remove whitespace

my_tab[,3] <- trimws( prettynum(formatc(my_tab[,3], format='f', digits=2), big.mark = ".", decimal.mark = ","))  

or keep numbers in data (not converting them character) , format them format.args argument in xtable.print

print(xtable(my_tab , align="llrr"), type="html", include.rownames = false,    html.table.attributes='class="table table-striped table-hover"',   format.args = list(big.mark = ".", decimal.mark = ",")) 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -