File: statcheckReport.R

package info (click to toggle)
r-cran-statcheck 1.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 764 kB
  • sloc: makefile: 2
file content (72 lines) | stat: -rw-r--r-- 2,888 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#' Generate HTML report for statcheck output
#' 
#' This function uses R Markdown to generate a nicely formatted HTML report of 
#' \code{\link{statcheck}} output.
#' 
#' This function temporarily saves the inserted \code{statcheck} output as an 
#' .RData file in the "output" folder in the statcheck package directory. This 
#' file is then called by the .Rmd template that is saved in the folder "rmd", 
#' also in the statcheck package directory. After the HTML report is generated, 
#' the .RData file is removed again.
#' 
#' @param statcheckOutput statcheck output of one of the following functions: 
#' \code{\link{statcheck}}, \code{\link{checkPDFdir}}, \code{\link{checkPDF}}, 
#' \code{\link{checkHTMLdir}}, \code{\link{checkHTML}}, or
#' \code{\link{checkdir}}.
#' @param outputFileName String specifying the file name under which you want to 
#' save the generated HTML report. The extension ".html" is automatically added, 
#' so doesn't need to be specified in this argument.
#' @param outputDir String specifying the directory in which you want to save 
#' the generated HTML report.
#' 
#' @return An HTML report, saved in the directory specified in the argument 
#' "outputDir".
#' 
#' @examples \dontrun{
#' 
#' # first generate statcheck output, for instance by using the statcheck() 
#' function
#' 
#' txt <- "blablabla the effect was very significant (t(100)=1, p < 0.001)"
#' stat <- statcheck(txt)
#' 
#' # next, use this output to generate a nice HTML report of the results
#' statcheckReport(stat, outputFileName="statcheckHTMLReport", 
#'                 outputDir="C:/mydocuments/results")
#' 
#' # you can now find your HTML report in the folder 
#' # "C:/mydocuments/results" under the name "statcheckHTMLReport.html".
#' 
#' }
#' 
#' @export

statcheckReport <-
  function(statcheckOutput,
           outputFileName,
           outputDir) {
    
    # set working directory to output file in statcheck package library
    currentWD <- getwd()
    setwd(system.file("inst/rmd", package = "statcheck"))
    
    # temporarily save statcheck output as RData in the selected working directory
    save(statcheckOutput, file = "statcheckOutput.RData")
    
    # run the markdown/knitr script
    statcheckReport_template <-
      system.file("rmd/statcheckReport_template.Rmd", package = "statcheck")
    rmarkdown::render(statcheckReport_template)
    
    # save/move the file in/to the specified output directory
    curDir <- system.file("rmd", package = "statcheck")
    file.rename(
      from = paste(curDir, "statcheckReport_template.html", sep = "/"),
      to = paste(outputDir, "/", outputFileName, ".html", sep = "")
    )
    
    # remove .RData file from package library folder
    file.remove(paste(curDir, "statcheckOutput.RData", sep = "/"))
    
    setwd(currentWD)
  }