首页 > 解决方案 > 运行具有相同参数的多个函数,但它跳过第一个函数并使用 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."
    }
]

标签: rjsonapiplumberrjson

解决方案


您不需要在管道工功能内打印。

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

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

推荐阅读