0

I am new to R language. I am trying to run the Tesseract OCR function if the uploaded file is pdf file, it seems like it always goes to the else part. I know there is an error in the if part but I have no clue to use what symbol.

Here are some part of the code

output$table <- renderTable({ 
if(is.null(input$file)) {return()}
read.table(file=input$file$datapath[input$file$name==input$Select], fill = TRUE, skipNul = TRUE)

# PDF file
if (input$file$datapath[input$file$name==input$Select] == "pdf"){
pdffile <- pdftools::pdf_convert(input$file$datapath[input$file$name==input$Select], dpi = 600)
text <- tesseract::ocr(pdffile)
}

# JPEG file
else{
  eng <- tesseract("eng")
  text <- tesseract::ocr(input$file$datapath[input$file$name==input$Select], engine = eng)
}
})
Phil
  • 7,287
  • 3
  • 36
  • 66
Ean Koh
  • 11
  • 2
  • The conditional is looking for an exact equality between `input$file$datapath[input$file$name==input$Select] ` and "pdf", so if the former is a full filename, you'd need to check that it _ends_ in "pdf" rather than _is_ "pdf" - so `if (grepl("\\.pdf$", input$file$datapath[input$file$name==input$Select])) {` – Gavin Kelly Apr 20 '20 at 11:23
  • I had an incomplete final line found by readTableHeader in read.table(file=input$file$datapath[input$file$name==input$Select] when I uploaded a jpg file. But according to https://stackoverflow.com/a/5996412/11953784 it seems like this solution does not solve the error since my file is jpg – Ean Koh Apr 21 '20 at 02:06
  • the grepl works, thank you – Ean Koh Apr 23 '20 at 21:00

0 Answers0