运行 具有相同参数的多重函数,但它跳过第一个函数并使用 R 中的水管工打印第二个函数

Run a Multiple function with same argument but it skip first function and print second function using plumber in R

我有一个主函数,它包括两个子函数,在函数 fun1 和 fun2 中都有相同的参数,函数打印 fun2 但无法在 swagger 控制台中使用管道工打印 fun1 不知道为什么?

这是我的代码

library(plumber)
library(tibble)

#* @get /Query 

detailData <- function(query = ""){
  print(query)
  library(gwasrapidd)
  fun1(query)
  fun2(query)

fun2函数输出,无法获取fun1函数

[
  {
    "study_id": "GCST002305",
    "pubmed_id": 24325915,
    "title": "Genome-wide association study identifies 25 known breast cancer susceptibility loci as risk factors for triple-negative breast cancer."
  },
  {
    "study_id": "GCST010100",
    "pubmed_id": 32424353,
    "title": "Genome-wide association study identifies 32 novel breast cancer susceptibility loci from overall and subtype-specific analyses."
  }
]

我想要单个对象中的两个函数,比如 fun1 是研究,fun2 是发布

[
    studies:{
        "study_id": "GCST002305",
        "gxe": false
    },
    {
        "study_id": "GCST010100",
        "gxe": false,
        "snp_count": 9700000
    },
    
    publication{
        "study_id": "GCST002305",
        "pubmed_id": 24325915,
        "title": "Genome-wide association study identifies 25 known breast cancer susceptibility loci as risk factors for triple-negative breast cancer."
    },
    {
        "study_id": "GCST010100",
        "pubmed_id": 32424353,
        "title": "Genome-wide association study identifies 32 novel breast cancer susceptibility loci from overall and subtype-specific analyses."
    }
]

只有返回的值(函数的最后一行)是自动打印的。如果你想同时打印,显式调用 print.

detailData <- function(query = ""){
  print(query)
  library(gwasrapidd)
  print(fun1(query))
  print(fun2(query))
}

您不需要在 plumber 函数中打印。

library(plumber)
library(tibble)
library(gwasrapidd)

#* @get /query 
function(query = ""){
    list(query, fun1(query), fun2(query))
}