我想在R中下载以下链接,在浏览器下载后保留文件名.
http://www.coingecko.com/price_charts/export/1/usd.xls
个
请注意,如果您通过浏览器下载该文件,则文件名将为‘btc-usd-Max.xls’.但是,如果我运行以下代码,文件名将为‘usd.xls’.然而,文件名‘btc-usd-Max.xls’传达了相关信息.是否可以使用R检索此‘btc-usd-max’名称?
link <- 'http://www.coingecko.com/price_charts/export/1/usd.xls'
download.file(url=link, destfile=basename(link), method='auto')
以下主题中提供的解决方案不能解决问题. R download.file to a folder keeping original name个
前面提到的解决方案依赖于content-disposition
,而content-disposition
并不存在.
library(httr)
hd <- HEAD(link)
filename <- gsub(".*name=", "", headers(hd)$`content-disposition`)
我已经try 使用HTtr包中的head()命令,并使用Download.file函数下载文件.