HenrikBengtsson / R.rsp
1
ps2pdf <- function(filename, path=NULL, opts=NULL, ..., force=FALSE, verbose=FALSE) {
2
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3
  # Validate arguments
4
  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5
  # Argument 'filename' & 'path':
6 0
  pathname <- Arguments$getReadablePathname(filename, path=path, mustExist=TRUE)
7

8
  # Argument 'opts':
9 0
  opts <- Arguments$getCharacters(opts)
10 0
  opts <- paste(opts, collapse=" ")
11

12
  # Argument 'force':
13 0
  force <- Arguments$getLogical(force)
14

15
  # Argument 'verbose':
16 0
  verbose <- Arguments$getVerbose(verbose)
17 0
  if (verbose) {
18 0
    pushState(verbose)
19 0
    on.exit(popState(verbose))
20
  }
21

22

23 0
  verbose && enter(verbose, "ps2pdf")
24 0
  verbose && cat(verbose, "PS pathname: ", pathname)
25

26 0
  filename <- basename(pathname)
27 0
  path <- dirname(pathname)
28

29 0
  filename2 <- gsub("[.]ps", ".pdf", filename)
30 0
  pathname2 <- Arguments$getWritablePathname(filename2, path=path)
31 0
  verbose && cat(verbose, "PDF pathname: ", pathname2)
32

33
  # Is output file up to date?
34 0
  isUpToDate <- FALSE
35 0
  if (!force && isFile(pathname2)) {
36 0
    date <- file.info(pathname)$mtime
37 0
    verbose && cat(verbose, "Source file modified on: ", date)
38 0
    outDate <- file.info(pathname2)$mtime
39 0
    verbose && cat(verbose, "Output file modified on: ", outDate)
40 0
    if (is.finite(date) && is.finite(outDate)) {
41 0
      isUpToDate <- (outDate >= date)
42
    }
43 0
    verbose && printf(verbose, "Output file is %sup to date.\n", ifelse(isUpToDate, "", "not "))
44
  }
45

46 0
  if (!isUpToDate || !isFile(pathname2)) {
47 0
    verbose && enter(verbose, "Calling ps2pdf")
48
    # Change working directory
49 0
    opwd <- getwd()
50 0
    on.exit(setwd(opwd))
51 0
    setwd(path)
52

53 0
    verbose && cat(verbose, "Working directory: ", getwd())
54 0
    verbose && cat(verbose, "Filename: ", filename)
55

56 0
    cmd <- sprintf("ps2pdf %s %s", opts, filename)
57 0
    system(cmd)
58

59 0
    verbose && exit(verbose)
60
  }
61

62
  # Sanity check
63 0
  pathname2 <- Arguments$getReadablePathname(pathname2, mustExist=TRUE)
64

65 0
  verbose && exit(verbose)
66

67 0
  invisible(pathname2)
68
} # ps2pdf()

Read our documentation on viewing source code .

Loading