簡體   English   中英

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

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

當我在管道工中發出 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"
}

請求得到一個有效的響應,一切都很好,除了在控制台中為每個請求顯示的丑陋警告消息。

關於如何解決它的任何想法?

原來它與 postBody 中使用的 JSON 有關。 如果 JSON 包含未轉義的制表符或換行符,則會引發警告。

在管道工存儲庫中關閉了一個問題,在最新版本 1.0.0 中不應再發生這種情況。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM