簡體   English   中英

如何在RStudio的源窗格中打印輸出

[英]How to print output in Source pane of RStudio

我有一個函數在R console打印所需的輸出,但我正在嘗試,是在RStudiosource pane中獲得與源代碼相同的輸出。

樣本功能 -

# Declare params for plumber api script----------------------------------
input <- c("A","B","C")
sample_print <- function(input){

  cat(for (i in length(input):1) {
    cat("\n#' @param",  input[i], sep =" " )
  },
  "\n#* @post /",
  sep = "")

}

sample_print(input)

輸出-

> sample_print(input)

#' @param C
#' @param B
#' @param A
#* @post /

注意 - 我知道可以copy/paste它。 但是,我有大量的輸出文本,我正在尋找一種可行的方法。

您可以先以文本格式保存腳本並使用sink()函數。 請參閱此鏈接https://www.statmethods.net/interface/io.html

暫無
暫無

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

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