Sean
Sean

Reputation: 11

Error using rvest download.file to download a pdf file

I would like to use download.file in rvest package to download a pdf. The link is as followed. https://www4.stat.ncsu.edu/~reich/ABA/Derivations3.pdf

my code is

download.file("https://www4.stat.ncsu.edu/~reich/ABA/Derivations3.pdf",destfile = "d3.pdf")

It does download a 1.7mb pdf file, but it's all blank when I open it. The other pdf files I tried to download has error messaged saying it is damaged.

Why the download.file command can't download pdf files?

Upvotes: 1

Views: 852

Answers (1)

Dan Wilson
Dan Wilson

Reputation: 4047

Since the library is intended for web scraping, and web pages are text, it stands to reason that the default write mode of download.file is ASCII.

Try specifying binary mode (mode = "wb") in your call.

download.file("https://www4.stat.ncsu.edu/~reich/ABA/Derivations3.pdf", destfile = "d3.pdf", mode = "wb")

Upvotes: 5

Related Questions