Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jrdnbradford/readmdtable
R 📦 for reading markdown tables into tibbles
https://github.com/jrdnbradford/readmdtable
data markdown markdown-parser markdown-table r r-package
Last synced: 2 days ago
JSON representation
R 📦 for reading markdown tables into tibbles
- Host: GitHub
- URL: https://github.com/jrdnbradford/readmdtable
- Owner: jrdnbradford
- License: gpl-3.0
- Created: 2024-09-04T17:16:54.000Z (23 days ago)
- Default Branch: main
- Last Pushed: 2024-09-25T18:35:30.000Z (2 days ago)
- Last Synced: 2024-09-26T02:37:40.229Z (2 days ago)
- Topics: data, markdown, markdown-parser, markdown-table, r, r-package
- Language: R
- Homepage: https://jrdnbradford.github.io/readMDTable/
- Size: 3.15 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE.md
Awesome Lists containing this project
README
---
output: github_document
---```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```[![R-CMD-check](https://github.com/jrdnbradford/readMDTable/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/jrdnbradford/readMDTable/actions/workflows/R-CMD-check.yaml)
[![CRAN Checks](https://badges.cranchecks.info/summary/readMDTable.svg?label=CRAN%20Status)](https://cran.r-project.org/web/checks/check_results_readMDTable.html)
[![CRAN version](https://img.shields.io/cran/v/readMDTable?logo=R&label=CRAN%20Version)](https://CRAN.R-project.org/package=readMDTable)
[![Dev version](https://img.shields.io/github/r-package/v/jrdnbradford/readMDTable/main?label=Dev%20Version&logo=github&labelColor=3e474f&logoColor=959da5)](https://github.com/jrdnbradford/readMDTable)
[![GitHub License](https://img.shields.io/github/license/jrdnbradford/readMDTable?logo=GNU&label=License)](https://www.gnu.org/licenses/gpl-3.0)
[![Codecov test coverage](https://codecov.io/gh/jrdnbradford/readMDTable/graph/badge.svg)](https://app.codecov.io/gh/jrdnbradford/readMDTable)
[![Monthly Downloads](https://cranlogs.r-pkg.org/badges/readMDTable?color=ff69b4)](https://CRAN.R-project.org/package=readMDTable)
[![Total Downloads](https://cranlogs.r-pkg.org/badges/grand-total/readMDTable?color=ff69b4)](https://CRAN.R-project.org/package=readMDTable)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](https://jrdnbradford.github.io/readMDTable/articles/rvest-benchmarks.html) to help determine if you should use readMDTable or rvest.
## Installation
Install the latest CRAN release with:
```{r, eval=FALSE}
install.packages("readMDTable")
```Install the development version from GitHub using pak:
```{r, eval=FALSE}
pak::pkg_install("jrdnbradford/readMDTable")
```or devtools:
```{r, eval=FALSE}
devtools::install_github("jrdnbradford/readMDTable")
```## Usage
```{r, echo=FALSE, include=FALSE}
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.
### From a File
Read in an example markdown table from the package:
```{r}
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:
```{r}
mtcars_file <- read_md_table_example("mtcars-split.md")extract_md_tables(mtcars_file, show_col_types = FALSE)
```### From a String
```{r}
read_md_table("| len | supp | dose |\n|---|---|---|\n| 4.2 | VC | 0.5 |")
```### From a URL
```{r}
read_md_table("https://raw.githubusercontent.com/jrdnbradford/readMDTable/main/inst/extdata/iris.md")
```
```{r}
extract_md_tables("https://raw.githubusercontent.com/jrdnbradford/readMDTable/main/inst/extdata/ToothGrowth.md")
```### Warnings and Messy Data
`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:
```{r}
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.