2017-06-07 41 views
0

我試圖使用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

什麼去哪裏?這個例子不是真正可重複的。也許'example%>%mutate(status = map_chr(code,GetStatusOfProcessing,tserver = server))' – alistaire

回答

0

也許是這樣的:

Output <- example %>% 
      mutate(Status = map_chr2(processor, code, GetStatusOfProcessing))