如何在 RStudio 的源窗格中打印输出
How to print output in Source pane of RStudio
我有一个函数可以在 R console
中打印所需的输出,但我正在尝试的是在 RStudio
的 source 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() 函数。
请参考这个link
https://www.statmethods.net/interface/io.html
我有一个函数可以在 R console
中打印所需的输出,但我正在尝试的是在 RStudio
的 source 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() 函数。 请参考这个link https://www.statmethods.net/interface/io.html