-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
92 lines (74 loc) · 4.17 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
---
output: github_document
---
```{r options, 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](https://rvest.tidyverse.org/).
## Installation
Install the latest [CRAN](https://CRAN.R-project.org/package=readMDTable) release with:
```{r cran-install, eval=FALSE}
install.packages("readMDTable")
```
Install the development version from [GitHub](https://github.com/jrdnbradford/readMDTable) using [pak](https://github.com/r-lib/pak):
```{r pak-install, eval=FALSE}
# install.packages("pak")
pak::pkg_install("jrdnbradford/readMDTable")
```
## Usage
```{r install, echo=FALSE, include=FALSE}
library(readMDTable)
```
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 example-1}
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 example-2}
mtcars_file <- read_md_table_example("mtcars-split.md")
extract_md_tables(mtcars_file, show_col_types = FALSE)
```
### From a String
```{r example-3}
read_md_table("| len | supp | dose |\n|---|---|---|\n| 4.2 | VC | 0.5 |\n")
```
### From a URL
```{r example-4}
read_md_table("https://raw.githubusercontent.com/jrdnbradford/readMDTable/main/inst/extdata/iris.md")
```
```{r example-5}
extract_md_tables("https://raw.githubusercontent.com/jrdnbradford/readMDTable/main/inst/extdata/ToothGrowth.md")
```
### Warnings and Messy Data
`read_md_table` will throw warnings by default if there are potential issues with the markdown table. In many cases it will still correctly read in the messy data if you use `force = TRUE`:
```{r example-6}
read_md_table(
" | Name | Age | City | Date |
|-------|-----|-------------|------------|
| Alice | 30 | | 2021/01/08 |
| Bob | 25 | Los Angeles | 2023/07/22
| Carol | 27 | Chicago | |",
force = TRUE
)
```
`extract_md_tables` will fail to recognize markdown tables that do not fit the markdown table format.