1
###########################################################################/**
2
# @RdocDefault compileRnw
3
#
4
# @title "Compiles a Rnw file"
5
#
6
# \description{
7
#  @get "title".
8
#  The compiler used depends on the content type.
9
# }
10
#
11
# @synopsis
12
#
13
# \arguments{
14
#   \item{filename, path}{The filename and (optional) path of the
15
#      document to be compiled.}
16
#   \item{...}{Additional arguments passed to the compiler function
17
#      used.}
18
#   \item{type}{A @character string specifying what content type of
19
#      Rnw file to compile.  The default (@NULL) is to infer the type
20
#      from the content of the file using @see "typeOfRnw".}
21
#   \item{verbose}{See @see "R.utils::Verbose".}
22
# }
23
#
24
# \value{
25
#   Returns the pathname of the generated document.
26
# }
27
#
28
# @author
29
#
30
# @keyword file
31
# @keyword IO
32
# @keyword internal
33
#*/###########################################################################
34
setMethodS3("compileRnw", "default", function(filename, path=NULL, ..., type=NULL, verbose=FALSE) {
35
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36
  # Validate arguments
37
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
38
  # Arguments 'filename' & 'path':
39 1
  pathname <- if (is.null(path)) filename else file.path(path, filename)
40 1
  if (!isUrl(pathname)) {
41 1
    pathname <- Arguments$getReadablePathname(pathname)
42
  }
43

44
  # Argument 'type':
45 1
  if (!is.null(type)) {
46 0
    type <- Arguments$getCharacter(type)
47
  }
48

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

56 1
  verbose && enter(verbose, "Compiling Rnw document")
57

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
  # Now we can infer the type of Rnw, i.e. Sweave or knitr
69 1
  if (is.null(type)) {
70 1
    type <- typeOfRnw(pathname)
71
  }
72 1
  verbose && cat(verbose, "Type of Rnw file: ", type)
73

74 1
  if (type == "application/x-sweave") {
75 1
    pathnameR <- compileSweave(filename, path=path, ..., verbose=verbose)
76 1
  } else if (type == "application/x-knitr") {
77 1
    pathnameR <- compileKnitr(filename, path=path, ..., verbose=verbose)
78 0
  } else if (type == "application/x-asciidoc-noweb") {
79 0
    pathnameR <- compileAsciiDocNoweb(filename, path=path, ..., verbose=verbose)
80
  } else {
81 0
    throw("Unknown value of argument 'type': ", type)
82
  }
83

84 1
  verbose && exit(verbose)
85

86 1
  pathnameR
87
}) # compileRnw()

Read our documentation on viewing source code .

Loading