#' Ler decisões
#'
#' @param diretorio Informar diretório
#' @param arquivos Se arquivos foram informados, diretório
#' é ignorado.
#' @param parallel Para leitura em paralelo. Usar no R
#' e não no RStudio.
#'
#' @return tibble com dados
#' @export
#'
#' @examples
#' \dontrun{
#' df <- ler_decisao_carf(diretorio = ".")
#' }
ler_decisao_carf <- function(diretorio = ".", arquivos = NULL, parallel = FALSE){
if (is.null(arquivos)){
arquivos <- list.files(path = diretorio, pattern = ".html", full.names = TRUE)
}
if (parallel == TRUE){
future::plan("multiprocess")
}
furrr::future_map_dfr(arquivos,purrr::possibly(~{
processo <- stringr::str_extract(.x,"\\d{17}")
acordao <- stringr::str_extract(.x,"\\d+(?=\\.html)")
x <- xml2::read_html(.x)
caminho <- x %>%
xml2::xml_find_all("//span[@id]") %>%
xml2::xml_attr("id") %>%
stringr::str_subset("formAcordaos")
purrr::map_dfr(caminho,purrr::possibly(~{
variavel <- stringr::str_extract(.x,"(?<=\\:).+")
valor <- xml2::xml_find_first(x,paste0('//span[@id=',"'",.x,"'",']')) %>%
xml2::xml_text()
tibble::tibble(variavel,valor) %>%
dplyr::filter(stringr::str_detect(variavel,"(^labe|id\\d+)",negate=TRUE))
},NULL)) %>%
tidyr::spread(variavel,valor) %>%
tibble::add_column(processo = processo, .before = 1) %>%
dplyr::select(acordao = numDecisao, tidyselect::everything())
},NULL), .progress = TRUE) %>%
dplyr::rename(dispositivo = "textDecisao") %>%
dplyr::rename(data_sessao = "dataSessao") %>%
dplyr::mutate(data_sessao = lubridate::dmy(data_sessao))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.