R/file_readr.R

Defines functions download_file read_pdf read_pdf_url

#library(pdftools)
#library(tools)




download_file <- function(url, download_location) {
  if (get_ram() < url_size(url)) {
    stop('Insufficient Memory to download file')
  } else {
    curl::curl_download(url, destfile = download_location)
  }
}



read_pdf <- function(file_path) {
  text <- pdf_text(file_path)
  text <- strsplit(text, split = '\n')

  text
}


read_pdf_url <- function(url) {
  # get tmp file name
  tmp_file <- construct_temp_file_name(ext = ".pdf")

  # download to tmp file
  download_file(url, tmp_file)

  #read tmp file
  text <- read_pdf(tmp_file)

  # remove tmp file
  unlink(tmp_file, force = T)

  return(text)

}
JTT94/rtoolbox documentation built on May 14, 2019, 12:08 p.m.