Kable correction

Lets try and resolve the issue I reported here . This code attempts to rectify the formatting issue by closing off the code chunk appropriately. I’ve also loaded the tidyverse packages as was done in this stackoverflow post.

  library(kableExtra)
  library(tidyverse)
  library(knitr)
  dt <- mtcars[1:15, 1:6]
  kable(dt, format = "html", align = "c") %>%
    kable_styling(bootstrap_options = c("striped", "hover"), 
                  full_width = T,
                  position = "left") %>%
    column_spec(1, width = "10em") %>% 
    column_spec(2, width = "7em") %>% 
    column_spec(3, width = "7em") %>% 
    column_spec(4, width = "7em") %>% 
    column_spec(5, width = "7em") %>% 
    column_spec(6, width = "7em") %>% 
    footnote(general = "Here is a general comments of the table. ",
             number = c("Footnote 1; ", "Footnote 2; "),
             alphabet = c("Footnote A; ", "Footnote B; "),
             symbol = c("Footnote Symbol 1; ", "Footnote Symbol 2"))
mpg cyl disp hp drat wt
Mazda RX4 21.0 6 160.0 110 3.90 2.620
Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875
Datsun 710 22.8 4 108.0 93 3.85 2.320
Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215
Hornet Sportabout 18.7 8 360.0 175 3.15 3.440
Valiant 18.1 6 225.0 105 2.76 3.460
Duster 360 14.3 8 360.0 245 3.21 3.570
Merc 240D 24.4 4 146.7 62 3.69 3.190
Merc 230 22.8 4 140.8 95 3.92 3.150
Merc 280 19.2 6 167.6 123 3.92 3.440
Merc 280C 17.8 6 167.6 123 3.92 3.440
Merc 450SE 16.4 8 275.8 180 3.07 4.070
Merc 450SL 17.3 8 275.8 180 3.07 3.730
Merc 450SLC 15.2 8 275.8 180 3.07 3.780
Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250
Note:
Here is a general comments of the table.
1 Footnote 1;
2 Footnote 2;
a Footnote A;
b Footnote B;
* Footnote Symbol 1;
Footnote Symbol 2

That does not have any impact.

Let’s try something different.

kable(dt) %>%
  kable_styling("striped") %>%
  add_header_above(c(" " = 1, "Group 1" = 2, "Group 2" = 2, "Group 3" = 2))
Group 1
Group 2
Group 3
mpg cyl disp hp drat wt
Mazda RX4 21.0 6 160.0 110 3.90 2.620
Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875
Datsun 710 22.8 4 108.0 93 3.85 2.320
Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215
Hornet Sportabout 18.7 8 360.0 175 3.15 3.440
Valiant 18.1 6 225.0 105 2.76 3.460
Duster 360 14.3 8 360.0 245 3.21 3.570
Merc 240D 24.4 4 146.7 62 3.69 3.190
Merc 230 22.8 4 140.8 95 3.92 3.150
Merc 280 19.2 6 167.6 123 3.92 3.440
Merc 280C 17.8 6 167.6 123 3.92 3.440
Merc 450SE 16.4 8 275.8 180 3.07 4.070
Merc 450SL 17.3 8 275.8 180 3.07 3.730
Merc 450SLC 15.2 8 275.8 180 3.07 3.780
Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250

Again, the format differs to that detailed in the vignette, no horizontal lines are produced.

Lastly, let’s try xtable using the image linked in this stackoverflow thread.

library(xtable)
print(xtable(dt), type = "html")
## <!-- html table generated in R 3.5.0 by xtable 1.8-2 package -->
## <!-- Sun Dec 16 14:03:33 2018 -->
## <table border=1>
## <tr> <th>  </th> <th> mpg </th> <th> cyl </th> <th> disp </th> <th> hp </th> <th> drat </th> <th> wt </th>  </tr>
##   <tr> <td align="right"> Mazda RX4 </td> <td align="right"> 21.00 </td> <td align="right"> 6.00 </td> <td align="right"> 160.00 </td> <td align="right"> 110.00 </td> <td align="right"> 3.90 </td> <td align="right"> 2.62 </td> </tr>
##   <tr> <td align="right"> Mazda RX4 Wag </td> <td align="right"> 21.00 </td> <td align="right"> 6.00 </td> <td align="right"> 160.00 </td> <td align="right"> 110.00 </td> <td align="right"> 3.90 </td> <td align="right"> 2.88 </td> </tr>
##   <tr> <td align="right"> Datsun 710 </td> <td align="right"> 22.80 </td> <td align="right"> 4.00 </td> <td align="right"> 108.00 </td> <td align="right"> 93.00 </td> <td align="right"> 3.85 </td> <td align="right"> 2.32 </td> </tr>
##   <tr> <td align="right"> Hornet 4 Drive </td> <td align="right"> 21.40 </td> <td align="right"> 6.00 </td> <td align="right"> 258.00 </td> <td align="right"> 110.00 </td> <td align="right"> 3.08 </td> <td align="right"> 3.21 </td> </tr>
##   <tr> <td align="right"> Hornet Sportabout </td> <td align="right"> 18.70 </td> <td align="right"> 8.00 </td> <td align="right"> 360.00 </td> <td align="right"> 175.00 </td> <td align="right"> 3.15 </td> <td align="right"> 3.44 </td> </tr>
##   <tr> <td align="right"> Valiant </td> <td align="right"> 18.10 </td> <td align="right"> 6.00 </td> <td align="right"> 225.00 </td> <td align="right"> 105.00 </td> <td align="right"> 2.76 </td> <td align="right"> 3.46 </td> </tr>
##   <tr> <td align="right"> Duster 360 </td> <td align="right"> 14.30 </td> <td align="right"> 8.00 </td> <td align="right"> 360.00 </td> <td align="right"> 245.00 </td> <td align="right"> 3.21 </td> <td align="right"> 3.57 </td> </tr>
##   <tr> <td align="right"> Merc 240D </td> <td align="right"> 24.40 </td> <td align="right"> 4.00 </td> <td align="right"> 146.70 </td> <td align="right"> 62.00 </td> <td align="right"> 3.69 </td> <td align="right"> 3.19 </td> </tr>
##   <tr> <td align="right"> Merc 230 </td> <td align="right"> 22.80 </td> <td align="right"> 4.00 </td> <td align="right"> 140.80 </td> <td align="right"> 95.00 </td> <td align="right"> 3.92 </td> <td align="right"> 3.15 </td> </tr>
##   <tr> <td align="right"> Merc 280 </td> <td align="right"> 19.20 </td> <td align="right"> 6.00 </td> <td align="right"> 167.60 </td> <td align="right"> 123.00 </td> <td align="right"> 3.92 </td> <td align="right"> 3.44 </td> </tr>
##   <tr> <td align="right"> Merc 280C </td> <td align="right"> 17.80 </td> <td align="right"> 6.00 </td> <td align="right"> 167.60 </td> <td align="right"> 123.00 </td> <td align="right"> 3.92 </td> <td align="right"> 3.44 </td> </tr>
##   <tr> <td align="right"> Merc 450SE </td> <td align="right"> 16.40 </td> <td align="right"> 8.00 </td> <td align="right"> 275.80 </td> <td align="right"> 180.00 </td> <td align="right"> 3.07 </td> <td align="right"> 4.07 </td> </tr>
##   <tr> <td align="right"> Merc 450SL </td> <td align="right"> 17.30 </td> <td align="right"> 8.00 </td> <td align="right"> 275.80 </td> <td align="right"> 180.00 </td> <td align="right"> 3.07 </td> <td align="right"> 3.73 </td> </tr>
##   <tr> <td align="right"> Merc 450SLC </td> <td align="right"> 15.20 </td> <td align="right"> 8.00 </td> <td align="right"> 275.80 </td> <td align="right"> 180.00 </td> <td align="right"> 3.07 </td> <td align="right"> 3.78 </td> </tr>
##   <tr> <td align="right"> Cadillac Fleetwood </td> <td align="right"> 10.40 </td> <td align="right"> 8.00 </td> <td align="right"> 472.00 </td> <td align="right"> 205.00 </td> <td align="right"> 2.93 </td> <td align="right"> 5.25 </td> </tr>
##    </table>

No go. It looks like I’ll have to come back to this one….

 
comments powered by Disqus