下载文件

R 数据导入进阶

Filip Schouwenaars

Instructor, DataCamp

示例:Excel

library(readxl)

read_excel("http://assets.datacamp.com/course/ importing_data_into_r/cities.xlsx")
错误:
'http://assets.datacamp.com/course/importing_data_into_r/cities.xlsx' 
在当前工作目录中不存在。
R 数据导入进阶

download.file()

url <- "http://assets.datacamp.com/
            course/importing_data_into_r/cities.xlsx"

dest_path <- file.path("~", "local_cities.xlsx")
download.file(url, dest_path)
// 省略显示下载进度的消息
read_excel(dest_path)
    Capital Population
1  New York   16044000
2    Berlin    3433695
3    Madrid    3010492
4 Stockholm    1683713
R 数据导入进阶

为何使用 download.file()?

  • 可复现性

  • 在 R 内发起 HTTP

    • 认证

    • 其他参数

    • httr(Hadley Wickham)

R 数据导入进阶

Passons à la pratique !

R 数据导入进阶

Preparing Video For Download...