R 📦 for reading markdown tables into tibbles
GPL-3.0 License
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
readMDTable helps convert raw markdown tables from a string, file, or URL to tibbles.
Many sites (like GitHub) convert markdown tables into HTML tables, making both available. See the vignette Benchmarking Against rvest to help determine if you should use readMDTable or rvest.
Install the latest CRAN release with:
install.packages("readMDTable")
Install the development version from GitHub using pak:
pak::pkg_install("jrdnbradford/readMDTable")
or devtools:
devtools::install_github("jrdnbradford/readMDTable")
devtools::load_all()
If you have a string, file, or URL whose entire content is just a markdown table, you should use read_md_table
which will return a tibble.
If the string, file, or URL is a markdown file that has other content besides just a table or tables, such as headings, paragraphs, etc, you should use extract_md_tables
which will parse the file and return a tibble or list of tibbles.
Read in an example markdown table from the package:
mtcars_file <- read_md_table_example("mtcars.md")
read_md_table(mtcars_file)
Read in an example markdown file that has multiple tables as well as headings and paragraphs:
mtcars_file <- read_md_table_example("mtcars-split.md")
extract_md_tables(mtcars_file, show_col_types = FALSE)
read_md_table("| len | supp | dose |\n|---|---|---|\n| 4.2 | VC | 0.5 |")
read_md_table("https://raw.githubusercontent.com/jrdnbradford/readMDTable/main/inst/extdata/iris.md")
extract_md_tables("https://raw.githubusercontent.com/jrdnbradford/readMDTable/main/inst/extdata/ToothGrowth.md")
read_md_table
will throw warnings if there are potential issues with the markdown table. In many cases it will still correctly read in the messy data:
read_md_table(
" | Name | Age | City | Date |
|-------|-----|-------------|------------|
| Alice | 30 | | 2021/01/08 |
| Bob | 25 | Los Angeles | 2023/07/22
| Carol | 27 | Chicago | |"
)
extract_md_tables
may fail to recognize markdown tables with improper formatting.