R 语言 download.file 的几点知识

R 语言中,不管是安装包,还是下载数据,很多时候都会用到download.file这个函数。如果你在安装包或者下载数据过程中出现中断,或者异常,想要判断是远程源服务器的问题,还是自身服务器的问题,还是网络故障,甚至于你想要换一种方法去继续你的下载,了解一下download.file还是很有帮助的。

9500bf20-ecbf-472d-a9d3-e8c38295a407.png

上面的链接是关于download.file函数非常详细的一个文档,个人非常关注就是它关于method参数设置和理解。

a2de359d-bd31-49a7-a6a6-5416adf0b973.png

BT娃小提示




If method="auto" is chosen (the default), the behavior depends on the platform:

  • On a Unix-alike method "libcurl" is used except "internal" for file:// URLs, where "libcurl" uses the library of that name (https://curl.se/libcurl/).

  • On Windows the "wininet" method is used apart from for ftps:// URLs where "libcurl" is tried. The "wininet" method uses the WinINet functions (part of the OS).


    Support for method "libcurl" is optional on Windows: use capabilities("libcurl") to see if it is supported on your build. It uses an external library of that name (https://curl.se/libcurl/) against which R can be compiled.


关于 download.file 的几点理解和值得注意的地方:


download.file 是来源于 R 自带的 utils 包的一个函数,使用 packageVersion("utils") 可以查看该包的版本。


8e8b6f17-5470-4dd2-989b-34ecc0b08781.jpg
2fb87548-a3d4-40c4-aab2-8b40a58888ad.jpg

在类 Unix 系统中,默认使用 "libcurl" 的方法,而对 file:// 的链接会使用 "internal" 的下载方法。


2fb87548-a3d4-40c4-aab2-8b40a58888ad.jpg

在 Windows 中,默认使用 "wininet" 的方法,对于 ftps:// 的资源会尝试使用 "libcurl" 的下载方法。


Method to be used for downloading files. Current download methods are "internal""wininet" (Windows  only) "libcurl", "wget" and "curl", and there is a value "auto".


8e8b6f17-5470-4dd2-989b-34ecc0b08781.jpg
2fb87548-a3d4-40c4-aab2-8b40a58888ad.jpg

注意 "libcurl""curl" 的区别,严格意义上,两者不是同一个东西。


2fb87548-a3d4-40c4-aab2-8b40a58888ad.jpg

相同点:


curllibcurl 都可以利用多种多样的协议来传输文件,包括 HTTP, HTTPS, FTP, FTPS, GOPHER, LDAP, DICT, TELNET and FILE 等。


2fb87548-a3d4-40c4-aab2-8b40a58888ad.jpg

不同点:


curl 是命令行工具,可以通过 shell 或脚本来运行 curlcurl 底层所使用的库是 libcurl


libcurl 是一个库,通常与别的程序绑定在一起使用,如命令行工具 curl 就是封装了 libcurl 库。所以我们也可以在你自己的程序或项目中使用 libcurl 以获得类似 curl 的强大功能。





The method can also be set through the option  "d ownload.file.method"  : see  options()   . A


  • 可以使用 options(download.file.method = "libcurl") 的方式指定全局下载的方法。

  • 参考:https://stackoverflow.com/a/63104633


ed644f51-fba3-43a3-8cd8-c88c9dc1dfa7.png

040e2119-a152-4b6d-96ad-fdd56776bc38.gif


R 包初学者指南

2021-02-05

ab4394c5-2926-499f-929b-5d218820d2b5.jpg

R 语言中 X11 相关的一些问题

2020-09-27

028baf1e-2356-43d9-b682-5f96bfe847b1.jpg

R 语言关于 SSL 证书异常处理笔记

2020-06-18

566fc473-ef64-4004-b11a-7dd5d84b67ba.jpg

ggplot2 调整绘图区域大小

2020-05-23

215f43c3-37f2-4e63-b723-90c6173ac3c8.jpg

R 语言绘制环状热图

2020-04-01

8c15c451-1836-4e93-a1fa-66431013224f.jpg

R 语言柱状图示例笔记

2020-03-20

d44a93d2-9ca1-48a4-838c-3e6f1bb771f8.jpg


cb67c7f4-f558-4239-a5e2-68827ab20833.png

本文分享自微信公众号 - 生信科技爱好者(bioitee)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

posted @ 2021-03-02 11:30  章鱼猫先生  阅读(109)  评论(0编辑  收藏  举报