Re: [問題] 利用R下載外匯資料

作者: TreeMan (好啊...)   2018-10-11 12:02:40
1. data_id_all: 指標代碼做成的字串
2. d1: 起始搜尋日期
3. d2: 當前日期
4. RKey: 你的Rkey
library(httr)
for(data_id in data_id_all){
file_name <- paste0(data_id, ".csv")
d1 <- "2005-01-01"
d2 <- as.character(Sys.Date())
url <- paste0("https://stock-ai.com/ddl?s=", data_id, "&r=RKey&d1=",
d1, "&d2=", d2)
GET(url, write_disk(file_name, overwrite=TRUE))
}
這樣應該會把更新到最新日期的檔案,存到你要的資料夾
我想到比較自動化的方式...
作者: ericchin0404 (凜魂)   2018-10-11 12:29:00
T大萬分感謝 這完全是我要的可以弱弱問write_disk跟裡面的參數overwrite是什麼意思嗎 我查了可是看不懂
作者: andrew43 (討厭有好心推文後刪文者)   2018-10-11 13:52:00
若目標檔案已存在要不要覆蓋
作者: ericchin0404 (凜魂)   2018-10-11 19:19:00
懂了感謝

Links booklink

Contact Us: admin [ a t ] ucptt.com