wwl
wwl

Reputation: 2065

download.file() in R doesn't work

I'm trying to download and save a pdf file using R.

This file displays perfectly in Chrome and Edge: http://www.cpppc.org:8082/efmisweb/ppp/projManage/perview.do?&ftpFileName=20170317105445289.pdf&content=efmisweb&xsg=:8083/

The following R code works without error:

download.file('http://www.cpppc.org:8082/efmisweb/ppp/projManage/perview.do?&ftpFileName=20170317105445289.pdf&content=efmisweb&xsg=:8083/', '20170317105445289.pdf', mode="wb")

R displays

trying URL 'http://www.cpppc.org:8082/efmisweb/ppp/projManage/perview.do?&ftpFileName=20170317105445289.pdf&content=efmisweb&xsg=:8083/'
Content type 'text/html; charset=UTF-8' length 2707 bytes
downloaded 2707 bytes

The only hint is that the file size is much smaller than what I would expect.

Indeed, when I open it using Adobe Acrobat, it gives me an error, saying it is either not a supported file type, or the file is damaged. What causes the error?

I noticed answers to other questions say you should include mode=wb, so I did that already.

Upvotes: 1

Views: 919

Answers (1)

MadMed
MadMed

Reputation: 36

With your link I had a 2707 bytes file. And with this link the file is 115 kilobytes.

download.file('http://www.cpppc.org:8082/efmisweb/ppp/projManage/xsg_perview.do?tokenid=undefined&fileName=20170317105445289.pdf',destfile = "Download", mode="wb")

Upvotes: 1

Related Questions