r - 将 df 帧值输入到 GET 函数 Web 查询中
问题描述
我正在尝试将数据框中的值列表输入到我的 get 函数中以进行 Web 查询,然后在每次迭代中循环。如果有人能够链接我一些进一步的资源来阅读和学习,将不胜感激。
以下是从 API 服务器中提取数据名称的代码。我计划使用purrr
迭代函数来检查它。列表中的输入将插入到变量 nameRFG_SELECT
中。
library(httr)
library(purrr)
## Call up Query Development Script
## Calls up every single rainfall data gauge across the entirety of QLD
wmip_callup <- GET('https://water-monitoring.information.qld.gov.au/cgi/webservice.pl?{"function":"get_site_list","version":"1","params":{"site_list":"MERGE(GROUP(MGR_OFFICE_ALL,AYR),GROUP(MGR_OFFICE_ALL,BRISBANE),GROUP(MGR_OFFICE_ALL,BUNDABERG),GROUP(MGR_OFFICE_ALL,MACKAY),GROUP(MGR_OFFICE_ALL,MAREEBA),GROUP(MGR_OFFICE_ALL,ROCKHAMPTON),GROUP(MGR_OFFICE_ALL,SOUTH_JOHNSTONE),GROUP(MGR_OFFICE_ALL,TOOWOOMBA))"}}')
# Turns API server data into JSON data.
wmip_dataf <- content(wmip_callup, type = 'application/json')
# Returns the values of the rainfall gauge site names and is the directory function.
list_var <- wmip_dataf[["_return"]][["sites"]]
# Combines all of the rainfall gauge data together in a list (could be used for giving file names / looping the data).
rfg_bind <- do.call(rbind.data.frame, list_var)
# Sets the column name of the combination data frame.
rfg_bind <- setNames(rfg_bind, "Rainfall Gauge Name")
rfg_select <- rfg_bind$`Rainfall Gauge Name`
# Attempts to filter list into query:
wmip_input <- GET('https://water-monitoring.information.qld.gov.au/cgi/webservice.pl?{"function":"get_ts_traces","version":"1","params":{"site_list":**rfg_select**,"datasource":"AT","varfrom":"10","varto":"10","start_time":"0","end_time":"0","data_type":"mean","interval":"day","multiplier":"1"}}') ```
解决方案
嘿,
经过一些工作,我找到了使用连接字符串的解决方案。
我设置了一个虚拟变量来帮助我选择数据值。
# Dummy Variable string:
wmip_url <- 'https://water-monitoring.information.qld.gov.au/cgi/webservice.pl?{"function":"get_ts_traces","version":"1","params":{"site_list":"varinput","datasource":"AT","varfrom":"10","varto":"10","start_time":"0","end_time":"0","data_type":"mean","interval":"day","multiplier":"1"}}'
# Dummy String, grabs ones value from the list.
rfg_individual <- rfg_select[2:2]
# Replaces the specified input
rfg_replace <- gsub("varinput", rfg_individual, wmip_url)
# Result
"https://water-monitoring.information.qld.gov.au/cgi/webservice.pl?{\"function\":\"get_ts_traces\",\"version\":\"1\",\"params\":{\"site_list\":\"001203A\",\"datasource\":\"AT\",\"varfrom\":\"10\",\"varto\":\"10\",\"start_time\":\"0\",\"end_time\":\"0\",\"data_type\":\"mean\",\"interval\":\"day\",\"multiplier\":\"1\"}}"
推荐阅读
- python - python:绘制和优化相同的函数
- python - PyQt:如果 mousePressEvent 发生在不同的小部件上,则 mouseReleaseEvent
- assembly - 用组件读取 CPU 温度
- spring - Spring Boot 在 Post Mapping 中不返回模板
- ios - 当使用 init 传递字符串的有效 url 时,URL(string: urlString) 返回 nil。怎么修?
- java - Java:从 PDF 中提取文本并显示为标题和项目单独的数组列表
- php - 错误消息“Aimeos 包上的类“\Aimeos\MShop\Index\Manager\PgSQL”不可用”
- node.js - 错误:找不到模块“graphql/validation/rules/PossibleTypeExtensions”
- amazon-web-services - 如何从 Cognito 身份池提供的身份凭证访问用户数据?
- jsf - Bean 不取值