tidyverse / rvest

Simple web scraping for R
https://rvest.tidyverse.org
Other
1.49k stars 341 forks source link

Add `convert` arg to html_table() to control whether to run conversion or not. #312

Closed yutannihilation closed 3 years ago

yutannihilation commented 3 years ago

Fix #311

I chose convert as the argument name because it's used some of tidyr's functions.

library(tibble)

d <- tibble(code = c("001", "002", "101", "102"),
            label = c("apple", "banana", "lemon", "orange"))

devtools::load_all("~/repo/rvest/")
#> Loading rvest

table_html <- knitr::kable(d, format = "html")
table_html <- as.character(table_html)

h <- table_html %>% 
  read_html()

html_table(h)
#> [[1]]
#> # A tibble: 4 x 2
#>    code label 
#>   <int> <chr> 
#> 1     1 apple 
#> 2     2 banana
#> 3   101 lemon 
#> 4   102 orange

html_table(h, convert = FALSE)
#> [[1]]
#> # A tibble: 4 x 2
#>   code  label 
#>   <chr> <chr> 
#> 1 001   apple 
#> 2 002   banana
#> 3 101   lemon 
#> 4 102   orange

Created on 2021-02-06 by the reprex package (v1.0.0)

hadley commented 3 years ago

Perfect, thanks!

yutannihilation commented 3 years ago

Thanks for reviewing!