-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b9f084
commit b14ac49
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#' Wrapper de pdftools::pdf_text | ||
#' | ||
#' @param arquivos Vetor de arquivos | ||
#' @param diretorio Alternativamente indicar onde se encontram os arquivos | ||
#' @param combinar Combinar as páginas num escalar? Padrão combinar | ||
#' @param basename Cominho completo ou apenas o nome do arquivo. Padrão apenas nome. | ||
#' | ||
#' @return tibble | ||
#' @export | ||
#' | ||
ler_pdfs <- function(arquivos = NULL, diretorio = ".", combinar = TRUE, basename = TRUE){ | ||
|
||
|
||
if(is.null(arquivos)) { | ||
arquivos <- list.files(diretorio, full.names = TRUE, | ||
pattern = "pdf$") | ||
} | ||
|
||
|
||
purrr::map_dfr(arquivos, purrr::possibly(~{ | ||
|
||
|
||
|
||
suppressMessages({ | ||
texto <- pdftools::pdf_text(.x) | ||
}) | ||
|
||
|
||
if(combinar) { | ||
texto <- stringr::str_c(texto, collapse = "\n") | ||
} | ||
|
||
arquivo <- .x | ||
|
||
if(basename){ | ||
|
||
arquivo <- basename(arquivo) | ||
} | ||
|
||
tibble::tibble(arquivo = arquivo, texto = texto) | ||
|
||
}, NULL), .progress = TRUE) | ||
|
||
|
||
} |