File: zzz.R

package info (click to toggle)
r-cran-tikzdevice 0.12.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,196 kB
  • sloc: ansic: 1,290; sh: 13; makefile: 12
file content (95 lines) | stat: -rwxr-xr-x 3,183 bytes parent folder | download | duplicates (3)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
.onLoad <- function(libname, pkgname) {

  # Ensure options are set.
  setTikzDefaults(overwrite = FALSE)

  # Perform a search for executable TeX compilers. R options, environment
  # variables and common paths will be checked. If PdfLaTeX can not be found,
  # loading of this package will be aborted as a LaTeX compiler is required in
  # order to determine string metrics. Other compilers, such as XeLaTeX, are
  # optional.
  foundLatex <- FALSE
  foundXelatex <- FALSE
  foundLualatex <- FALSE

  latexLocs <- list(
    OPTION("tikzLatex"),
    ENV_VAR("R_LATEXCMD"),
    ENV_VAR("R_PDFLATEXCMD"),
    OPTION("latexcmd"),
    PATH("pdflatex"),
    PATH("latex")
  )

  # Only check for xelatex and lualatex in the options and the PATH variable
  # since there are no R environment variables for these compilers.
  xelatexLocs <- list(
    OPTION("tikzXelatex"),
    PATH("xelatex")
  )

  lualatexLocs <- list(
    OPTION("tikzLualatex"),
    PATH("lualatex")
  )

  # Non-Windows users are likely to use some derivative of TeX Live. This next
  # test primarily covers the fact that R.app does not include `/usr/texbin` on
  # the search path on OS X.
  if (.Platform[["OS.type"]] == "unix") {
    # Using explicit list insertion because the `c` function drops attributes
    # and thus destroys S3 objects. Writing 3 new class methods for PATH,
    # OBJECT and ENV_VAR is just overkill.
    latexLocs[[length(latexLocs) + 1]] <- PATH("/usr/texbin/pdflatex")
    xelatexLocs[[length(xelatexLocs) + 1]] <- PATH("/usr/texbin/xelatex")
    lualatexLocs[[length(lualatexLocs) + 1]] <- PATH("/usr/texbin/lualatex")
  }

  for (latexPath in latexLocs) {
    if (isExecutable(latexPath)) {
      foundLatex <- TRUE
      options(tikzLatex = as.character(latexPath), tikzLatexDefault = as.character(latexPath))
      break
    }
  }

  for (xelatexPath in xelatexLocs) {
    if (isExecutable(xelatexPath)) {
      foundXelatex <- TRUE
      options(tikzXelatex = as.character(xelatexPath), tikzXelatexDefault = as.character(xelatexPath))
      break
    }
  }

  for (lualatexPath in lualatexLocs) {
    if (isExecutable(lualatexPath)) {
      foundLualatex <- TRUE
      options(tikzLualatex = as.character(lualatexPath), tikzLualatexDefault = as.character(lualatexPath))
      break
    }
  }

  if (!foundLatex) {
    warning(
      "\n\ntikzDevice: No appropriate LaTeX compiler could be found.\n",
      "Access to LaTeX is required in order for the TikZ device\n",
      "to produce output.\n\n",
      "The following places were tested for a valid LaTeX compiler:\n\n\t",
      paste(sapply(latexLocs, format), collapse = "\n\t"),
      "\n\nIf you have a working LaTeX compiler, try one of the\n",
      "following solutions:",

      "\n\n\tSet the path to your compiler as the value of either latexcmd or",
      "\n\ttikzLatex in .Rprofile using options().",

      "\n\n\tSet the path to your compiler as the value of either R_LATEXCMD or",
      "\n\tR_PDFLATEXCMD in .Renviron.",

      "\n\n\tEnsure the folder containing your compiler is included in PATH.\n"
    )
  }
}

# Any variables defined in here will be hidden
# from normal users.
.tikzInternal <- new.env()