Here are the examples of the r api knitr-combine_words taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
19
File: buscar_noticias_gov_sp.R, author: beatrizmilz, license: GNU General Public License v3.0
parse_item_gov_sp < - function(item_lista) {
classes_div < - item_lista %>% rvest::html_attr("class") %>%
stringr::str_split(pattern = " ") %>% purrr::pluck(1)
id < - classes_div[1] %>% stringr::str_remove("post-")
categorias < - classes_div %>% tibble::as_tibble() %>% dplyr::filter(stringr::str_starts(value,
"category-")) %>% dplyr::mutate(categorias = stringr::str_remove(value,
"category-"), categorias = stringr::str_replace_all(categorias,
"-", " ")) %>% dplyr::pull(categorias) %>% knitr::combine_words(sep = ", ",
and = "") %>% as.character()
tags < - classes_div %>% tibble::as_tibble() %>% dplyr::filter(stringr::str_starts(value,
"tag-")) %>% dplyr::mutate(tags = stringr::str_remove(value,
"tag-"), tags = stringr::str_replace_all(tags, "-", " ")) %>%
dplyr::pull(tags) %>% knitr::combine_words(sep = ", ",
and = "") %>% as.character()
if (length(tags) == 0) {
tags < - NA
}
classe_infos < - item_lista %>% rvest::html_element(xpath = ".//*[@class=\"col-md-5 category-infos\"]")
if (is.na(classe_infos[1])) {
classe_infos_antigas < - item_lista %>% rvest::html_element(xpath = ".//*[@class=\"no-thumbnail category-infos\"]")
data_bruta < - classe_infos_antigas %>% rvest::html_element("span") %>%
rvest::html_text()
data < - data_bruta %>% tibble::as_tibble() %>% tidyr::separate(col = value,
into = c("data", "horario"), sep = "-") %>% dplyr::mutate(dplyr::across(tidyselect::everything(),
stringr::str_trim), data = lubridate::dmy(data))
classe_titulo < - classe_infos_antigas %>% rvest::html_element("h3")
url_noticia < - classe_infos_antigas %>% rvest::html_element("a") %>%
rvest::html_attr("href")
titulo < - classe_infos_antigas %>% rvest::html_element("h3") %>%
rvest::html_text()
chamada < - classe_infos_antigas %>% rvest::html_element("p") %>%
rvest::html_text()
}
else {
data_bruta < - classe_infos %>% rvest::html_element("span") %>%
rvest::html_text()
data < - data_bruta %>% tibble::as_tibble() %>% tidyr::separate(col = value,
into = c("data", "horario"), sep = "-") %>% dplyr::mutate(dplyr::across(tidyselect::everything(),
stringr::str_trim), data = lubridate::dmy(data))
classe_titulo < - classe_infos %>% rvest::html_element("h3")
url_noticia < - classe_titulo %>% rvest::html_element("a") %>%
rvest::html_attr("href")
titulo < - classe_titulo %>% rvest::html_text()
chamada < - classe_infos %>% rvest::html_element("p") %>%
rvest::html_text()
}
classe_thumbnail < - item_lista %>% rvest::html_element(xpath = ".//*[@class=\"col-md-3 category-thumbnail\"]")
if (is.na(classe_thumbnail[1])) {
img_url < - NA
img_alt < - NA
url_noticia_img < - NA
}
else {
url_noticia_img < - classe_thumbnail %>% rvest::html_element("a") %>%
rvest::html_attr("href")
img_url < - classe_thumbnail %>% rvest::html_element("img") %>%
rvest::html_attr("src")
img_alt < - classe_thumbnail %>% rvest::html_element("img") %>%
rvest::html_attr("alt")
}
tibble::tibble(id, data, url_noticia, titulo, chamada, categorias,
tags, img_url, img_alt, url_noticia_img)
}