解决在R中使用管道工库时警告“ if(stri_startswith_fixed(body,“ {”)){:...“

时间:2019-11-24 16:51:16

标签: r plumber

我在水管工中发出POST请求时当前出现此错误:

Warning in if (stri_startswith_fixed(body, "{")) { :
  the condition has length > 1 and only the first element will be used
Warning in if (stri_startswith_fixed(qs, "?")) { :
  the condition has length > 1 and only the first element will be used

这就是我的功能:

#' Get results from Two Sample t-test
#' @serializer unboxedJSON
#' @param group:character The group col you would like to group data by
#' @param variable:character The variable you would like to be compared between groups
#' @post /twosamplettest/<group>/<variable>
function(req, group, variable) {
    data_as_df <- fromJSON(req$postBody)

    results <- t.test(get(variable) ~ get(group), data=data_as_df)

    group_mean_df <- extractGroupsAndMeansFromTTestResults(results)

    test_results <- list(pvalue=results$p.value, group_stats=as.data.frame(group_mean_df)))

    test_results
}

即使是这样简单的事情也会给出相同的警告:

#' @post /test
function(message){
  "Testerino"
}

该请求获得了有效的响应,除了在控制台中针对每个提出的请求显示的丑陋警告消息之外,其他所有内容都很好。

有任何解决方法的想法吗?

2 个答案:

答案 0 :(得分:0)

结果证明,这与postBody中使用的JSON有关。如果JSON包含未转义的选项卡或换行符,则会引发警告。

答案 1 :(得分:0)

在水管工仓库中有一个issue已关闭,在最新的1.0.0版本中不再应该发生这种情况。