【发布时间】:2019-06-13 05:29:30
【问题描述】:
我正在尝试下载我从 Google 表单(实际上是该表单的回复表)研究的鸟类的图像。在这个简短的数据集中,我有每只鸟的 ID、捕获日期,以及从不同角度(尾巴、frontPop 等)拍摄的多张鸟的图像。
我想遍历这个数据集,下载每种类型的图像,并通过鸟的 ID、捕获日期和图像类型(对应于列名)来命名:
189307140_2019-01-14_tail.jpg
我可以使用“curl”包从电子表格中的每个 Google Drive 链接下载图像,如下所示:
library(curl)
curl_download(url = 'https://drive.google.com/uc?export=download&id=1kra8bSf4WMpoK8BTyFip2OxmUuz30Thl',
destfile = 'bird.jpg')
但我被困在一个更优雅的循环中(在我的数据集中的每个鸟和照片类型上)......
以下是数据示例:
dat <- structure(list(markerID = c(189307136L, 189307145L, 183337360L
), date = structure(c(17907, 17910, 17910), class = "Date"),
tail = c("https://drive.google.com/uc?export=download&id=13S9s_j6acfndEz4HbpG-v2ZRyT8LLgji",
"https://drive.google.com/uc?export=download&id=19XpBTLws94wtCtgPF6oXKM_GZ_cV4oMf",
"https://drive.google.com/uc?export=download&id=1I5zA8tJdEv26EzI9rwBSN5tVsASyT4Cl"
), frontPop = c("https://drive.google.com/uc?export=download&id=1lJgl3hin9sWQcV40aJgdYPQM6jzch2Lb",
"https://drive.google.com/uc?export=download&id=1QdB1KmyHrlKkTlux0fkyI1Aw-Pe15sYF",
"https://drive.google.com/uc?export=download&id=1xqNT9CPVfMj2ksxqMONGbWXyJKaKtLuR"
), backPop = c("https://drive.google.com/uc?export=download&id=1YAe4S7_LIrLsbOW2qCBuWjyOr_SgT54T",
"https://drive.google.com/uc?export=download&id=1QOC8rPDjWfy6PVSaXFycf4jDyUnV-Vbv",
"https://drive.google.com/uc?export=download&id=1Gyo4lXgp0nXbsdd0jA_kk1m2jW8RGGIY"
)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-3L))
# A tibble: 3 x 5
markerID date tail frontPop backPop
<int> <date> <chr> <chr> <chr>
1 189307136 2019-01-11 https://drive.google.com/uc?export=download… https://drive.google.com/uc?export=download… https://drive.google.com/uc?export=download…
2 189307145 2019-01-14 https://drive.google.com/uc?export=download… https://drive.google.com/uc?export=download… https://drive.google.com/uc?export=download…
3 183337360 2019-01-14 https://drive.google.com/uc?export=download… https://drive.google.com/uc?export=download… https://drive.google.com/uc?export=download…
【问题讨论】: