HenrikBengtsson / R.rsp
1
###########################################################################/**
2
# @RdocDefault compileSweave
3
#
4
# @title "Compiles a Sweave file"
5
#
6
# \description{
7
#  @get "title".
8
# }
9
#
10
# @synopsis
11
#
12
# \arguments{
13
#   \item{filename, path}{The filename and (optional) path of the
14
#      Sweave document to be compiled.}
15
#   \item{...}{Additional arguments passed to @see "compileLaTeX".}
16
#   \item{outPath}{The output and working directory.}
17
#   \item{postprocess}{If @TRUE, and a postprocessing method exists for
18
#      the generated product, it is postprocessed as well.}
19
#   \item{verbose}{See @see "R.utils::Verbose".}
20
# }
21
#
22
# \value{
23
#   Returns the pathname of the generated document.
24
# }
25
#
26
# @author
27
#
28
# \seealso{
29
#   Internally, @see "utils::Sweave" is used.
30
# }
31
#
32
# @keyword file
33
# @keyword IO
34
# @keyword internal
35
#*/###########################################################################
36
setMethodS3("compileSweave", "default", function(filename, path=NULL, ..., outPath=".", postprocess=TRUE, verbose=FALSE) {
37
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
38
  # Validate arguments
39
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
40
  # Arguments 'filename' & 'path':
41 1
  pathname <- if (is.null(path)) filename else file.path(path, filename)
42 1
  if (!isUrl(pathname)) {
43 1
    pathname <- Arguments$getReadablePathname(pathname)
44
  }
45

46
  # Arguments 'outPath':
47 1
  outPath <- Arguments$getWritablePath(outPath)
48 1
  if (is.null(outPath)) outPath <- "."
49

50
  # Argument 'verbose':
51 1
  verbose <- Arguments$getVerbose(verbose)
52 1
  if (verbose) {
53 1
    pushState(verbose)
54 1
    on.exit(popState(verbose))
55
  }
56

57 1
  verbose && enter(verbose, "Compiling Sweave document")
58
  # Download URL?
59 1
  if (isUrl(pathname)) {
60 0
    verbose && enter(verbose, "Downloading URL")
61 0
    url <- pathname
62 0
    verbose && cat(verbose, "URL: ", url)
63 0
    pathname <- downloadFile(url, verbose=less(verbose,50))
64 0
    verbose && cat(verbose, "Local file: ", pathname)
65 0
    verbose && exit(verbose)
66
  }
67

68 1
  pathname <- getAbsolutePath(pathname)
69 1
  verbose && cat(verbose, "Sweave pathname (absolute): ", pathname)
70 1
  verbose && printf(verbose, "Input file size: %g bytes\n", file.info(pathname)$size)
71 1
  verbose && cat(verbose, "Output and working directory: ", outPath)
72

73 1
  opwd <- "."
74 1
  on.exit(setwd(opwd), add=TRUE)
75 1
  if (!is.null(outPath)) {
76 1
    opwd <- setwd(outPath)
77
  }
78

79 1
  pathname2 <- Sweave(pathname)
80 1
  pathname2 <- getAbsolutePath(pathname2)
81 1
  setwd(opwd); opwd <- "."
82

83 1
  res <- RspFileProduct(pathname2)
84 1
  verbose && print(verbose, res)
85

86
  # Postprocess?
87 1
  if (postprocess) {
88 0
    res <- process(res, outPath=outPath, recursive=TRUE, verbose=verbose)
89
  }
90

91 1
  verbose && exit(verbose)
92

93 1
  res
94
}) # compileSweave()

Read our documentation on viewing source code .

Loading