如何从R包中的函数生成html/pdf报告

如何从R包中的函数生成html/pdf报告,r,report,r-markdown,knitr,R,Report,R Markdown,Knitr,我想在我的R包中包含一个函数,在给定一些输入数据的情况下生成html/pdf报告 例如,让我们设想以下函数: #' @title Nice Report #' @description It generates a nice summary report #' @param x data.frame with column `column_whatever` #' @param y data frame with column `column_whatever` #' @param output

我想在我的R包中包含一个函数,在给定一些输入数据的情况下生成html/pdf报告

例如,让我们设想以下函数:

#' @title Nice Report
#' @description It generates a nice summary report
#' @param x data.frame with column `column_whatever`
#' @param y data frame with column `column_whatever`
#' @param outputFormat Output format: either `pdf`(default) or `html` 
#' @return Either html/pdf summary report
#' @keywords QC, report
#' @examples
#' render_a_nice_report(x = data_example1, y = data_example2)
#' @export
render_a_nice_report <- function(x, 
                                 y, 
                                 outputFormat = "pdf"){

    # do some stuff with x and y
    z <- merge(x, y, by=(column_whatever))

    # Nicely print the data frame:

    #' ### Head of table resulting from merging x and y

    knitr::kable(head(z))

    #' ### Title 1: Distribution of variable 1

    plot1 <- ggplot(z) + geom_density(aes(v1))

    print(plot1)

    #' Some description of the plot above

    # Do something else to z

    k <- mypackage::do_whatever(z)

    #' ### Title 2: Histogram of Variable Var2

    plot2 <- ggplot(k) + geom_histogram(aes(var2))

# and finish rendering the report
}
#@title漂亮的报告
#@description它生成了一个很好的摘要报告
#“@param x data.frame和列`column_`
#“@param y数据框,列为`column\u`
#“@param outputFormat输出格式:pdf`(默认)或html`
#“@返回html/pdf摘要报告
#“@QC,报告
#“@示例
#'呈现一个漂亮的报告(x=data\u示例1,y=data\u示例2)
#“@出口

render_a_nice_report下面是一个包含各种可视化/报告功能的包示例:哇!这不仅仅是我想要的,包装本身也很棒!谢谢!下面是一个包含各种可视化/报告功能的软件包示例:哇!这不仅仅是我想要的,包装本身也很棒!谢谢!