I want to download some files, but I want to save them with their default names, that is, the name which come up when url is opened through a browser. I found one thread for the same issue in python here but not for R
Here is my current code, which download labour supply in a particular format for 47 states of Japan:
n = 47
str1 = "https://www.e-stat.go.jp/en/stat-search/file-download?statInfId=00003164"
str2.1 = seq(from =3894, by=15,length.out=24)
str2.2 = seq(from =4259, by=15,length.out=23)
str2 = c(str2.1, str2.2)
str3 = "&fileKind=1"
destfiles = c(paste0("010_0",1:9,".csv"),paste0("010_",10:n,".csv"))
url = paste0(str1,str2,str3)
mapply(download.file, url, destfile=destfiles, method='curl')
Note that how I create file numbers using sequence function. Ideally, every 15th file is the one I need as each state has 15 files pertaining to it, but somewhere in middle they include some extra files and file numbers' change. If I provide destination file names myself, I will not get to know if I have downloaded the correct file by looking at its name. But if I can somehow get the default names, I will immediately get to know whether I have downloaded an incorrect file by just looking at its name. The names are in the format "010_xx.csv" where xx is the file number.
To see the default names, you can get url[[1]]
and url[[2]]
either through the code or from these links: url1, url2 and open them with browser.