Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

tm readPDF: Error in file(con, "r") : cannot open the connection

I have tried the example code recommended in the tm::readPDF documentation:

library(tm)

if(all(file.exists(Sys.which(c("pdfinfo", "pdftotext"))))) {
    uri <- system.file(file.path("doc", "tm.pdf"), package = "tm")
    pdf <- readPDF(PdftotextOptions = "-layout")(elem = list(uri = uri),
                                                 language = "en",
                                                 id = "id1")
    pdf[1:13]
}

But I get the following error (which occurs after calling the function returned by readPDF):

Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file 'C:DOCUME~1TomasLOCALS~1TempRtmpU33iWopdfinfo31c2bd5762a': No such file or directory

Note that I have installed all xpdf binaries to current directory (but this is handled by the if condition).

EDIT: found out this is a bug. What would be the easiest workaround?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Did some debugging and see it fails in tm:::pdfinfo():

status <- system2("pdfinfo", shQuote(normalizePath(file)), 
        stdout = outfile)

This command doesn't create the outfile. According to Redirect system2 stdout to a file on windows this is a bug!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...