--- title: "Tables and lists" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Tables and lists} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set(collapse = TRUE, comment = "#>") ``` ```{r} library(zuhtml) ``` ## Tables `html_table()` reads one `` into a data frame; `html_tables()` finds tables and reads each. Every column is character, so identifiers keep their leading zeros. ```{r} doc <- html_parse("
CodePrice
001212.50
00349.00
") html_table(html_element(doc, "table")) ``` ### Spans A value that spans rows or columns is repeated in every slot it covers, and a column's name joins the header rows above it with `" / "`: ```{r} doc <- html_parse("
RegionSales
20252026
North1012
South79
811
") html_table(html_element(doc, "table")) ``` `rowspan="0"` runs to the end of its row group, and a rowspan larger than the rows left in its group is cut there. Two cells whose spans cover the same slot are an error, not a silent overwrite: ```{r} doc <- html_parse("
ab
c
") try(html_table(html_element(doc, "table"))) ``` ### Headers With the default `header = "auto"`, the rows of `` are headers if there is one, otherwise the leading rows made only of `` cells. A `` among ``s is a row label, not a header. Use `TRUE`, `FALSE` or row numbers to choose explicitly: ```{r} doc <- html_parse("
nameqty
tea2
") tab <- html_element(doc, "table") html_table(tab) html_table(tab, header = TRUE) ``` Blank names become `V1`, `V2`, ...; duplicate names get `make.unique()` suffixes. Rows are read head first, then bodies, then footers, and footers are data. Rows of a table nested inside a cell stay out of the outer table, and the nested table's text stays out of the cell. Missing slots (in ragged rows) are `NA`; an empty cell is `""`. Mark placeholders as missing with `na`: ```{r} doc <- html_parse("
ab
1-
2
") html_table(html_element(doc, "table"), na = "-") ``` ## Lists `html_list()` reads one `