简体   繁体   English

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

[英]Resolving "Warning in if (stri_startswith_fixed(body, "{")) { :..." when using the plumber library in R

Currently getting this error when I make a POST request in 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

This is what my function looks like:这是我的函数的样子:

#' 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
}

Even something as simple as this gives the same warning:即使像这样简单的事情也会发出同样的警告:

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

The request gets a valid response and everything is all good except for that ugly warning message that shows up in the console for every request made.请求得到一个有效的响应,一切都很好,除了在控制台中为每个请求显示的丑陋警告消息。

Any ideas on how to resolve it?关于如何解决它的任何想法?

Turns it out it had to do with the JSON being used in the postBody.原来它与 postBody 中使用的 JSON 有关。 If the JSON contains unescaped tabs or newlines, the warning is thrown.如果 JSON 包含未转义的制表符或换行符,则会引发警告。

在管道工存储库中关闭了一个问题,在最新版本 1.0.0 中不应再发生这种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM