-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
96 lines (76 loc) · 3.92 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
---
output: github_document
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# readMDTable <a href="https://jrdnbradford.github.io/readMDTable/"><img src="man/figures/logo.png" align="right" height="139" alt="readMDTable website" /></a>
<!-- badges: start -->
[![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)
<!-- badges: end -->
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.