【发布时间】:2020-11-03 01:04:09
【问题描述】:
我正在尝试使用API 确定给定日期的日出时间
所以我有一个这样的数据框
Date
1 2018-01-03
2 2018-01-03
3 2018-01-04
4 2018-01-08
5 2018-01-09
虽然我可以在没有粘贴语句的情况下使其工作,但当我将其放入 mutate 时,它不起作用并返回错误:
dates <- structure(list(Date = c("2018-01-03", "2018-01-03", "2018-01-04",
"2018-01-08", "2018-01-09")), row.names = c(NA, 5L), class = "data.frame")
dates %>%
mutate(sunrise = as.character(fromJSON(rawToChar(GET(paste0("https://api.sunrise-sunset.org/json?lat=40.730610&lng=-73.935242&date=", Date))$content))$results[1])
)
ERROR:
Error: Problem with `mutate()` input `sunrise`.
x length(url) == 1 is not TRUE
i Input `sunrise` is `as.character(...)`.
这里的目标是我希望每天都有一个新的日出列。如果我更改 paste0 字段并给它一个确切的字符串,但不是在 mutate 中,它可以完美地工作,我不知道为什么......
【问题讨论】: