我正在尝试使用purrr
填充数据框中的新列。
该框架包含来自服务器的端点列表,然后我有一个使用httr
获取端点状态的函数,但我似乎无法使其工作?
示例是:
require(tibble)
require(purrr)
require(httr)
require(RCurl)
require(dplyr)
example = tibble(
processor = c('A', 'B', 'C'),
code = c('s3zsf3', 'a2ssf3', 'g6zsf6')
)
GetStatusOfProcessing <- function(identifier, tserver) {
url = paste0( tserver,identifier )
data = content(GET(url))
data$runStatus # this is a string
}
server = 'http://localhost:8080/'
Output <- example %>%
map(GetStatusOfProcessing(., server))
Expected_Output_example = tibble(
processor = c('A', 'B', 'C'),
code = c('s3zsf3', 'a2ssf3', 'g6zsf6'),
Status = c('RUNNING', 'RUNNING', 'RUNNING')
)
如何使用map
按行ID正确输入,或者使用错误的函数?
答案 0 :(得分:0)
也许是这样的:
Output <- example %>%
mutate(Status = map_chr2(processor, code, GetStatusOfProcessing))