no-segfault.Rin 4.99 KB
Newer Older
1 2 3 4 5 6 7 8 9
###-*- R -*-
###--- This "foo.Rin" script is only used to create the real script "foo.R" :

###--- We need to use such a long "real script" instead of a for loop,
###--- because "error --> jump_to_toplevel", i.e., outside any loop.

core.pkgs <-
{x <- installed.packages(file.path(R.home(), "library"));
    x[x[,"Priority"] %in% "base", "Package"]}
10
core.pkgs <-
11
    core.pkgs[- match(c("methods", "parallel", "tcltk", "stats4"), core.pkgs, 0)]
12
## move methods to the end because it has side effects (overrides primitives)
13 14 15
## stats4 requires methods
core.pkgs <- c(core.pkgs, "methods", "stats4")

16 17 18
stop.list <- vector("list", length(core.pkgs))
names(stop.list) <- core.pkgs

19
## -- Stop List for base/graphics/utils:
20
edit.int <- c("fix", "edit", "edit.data.frame", "edit.matrix",
21
              "edit.default", "vi", "file.edit",
22
              "emacs", "pico", "xemacs", "xedit", "RSiteSearch", "help.request")
23

24 25
## warning: readLines will work, but read all the rest of the script
## warning: trace will load methods.
26
## warning: rm and remove zap c0, l0, m0, df0
27
## warning: parent.env(NULL) <- NULL creates a loop
28
## warning: browseVignettes lanuches many browser processes.
29
## news, readNEWS, rtags are slow, and R-only code.
30
misc.int <- c("browser", "browseVignettes", "bug.report", "checkCRAN",
31
              "getCRANmirrors", "lazyLoad", "menu", "repeat",
32
              "readLines", "package.skeleton", "trace", "recover",
33 34 35
              "rm", "remove", "parent.env<-",
              "builtins", "data", "help", "news", "rtags", "vignette",
              "installed.packages")
36 37
inet.list <- c(apropos("download\\."),
               apropos("^url\\."), apropos("\\.url"),
38
               apropos("packageStatus"),
39
               paste(c("CRAN", "install", "update", "old"), "packages", sep="."))
40 41 42
socket.fun <- apropos("socket")
## "Interactive" ones:
dev.int <- c("X11", "x11", "pdf", "postscript",
43
             "xfig", "jpeg", "png", "pictex", "quartz",
44 45 46
             "svg", "tiff", "cairo_pdf", "cairo_ps",
             "getGraphicsEvent")
misc.2 <- c("asS4", "help.start", "browseEnv", "make.packages.html",
47 48
            "gctorture", "q", "quit", "restart", "try",
            "read.fwf", "source",## << MM thinks "FIXME"
49
            "data.entry", "dataentry", "de", apropos("^de\\."),
50
            "chooseCRANmirror", "setRepositories", "select.list", "View")
51 52 53
if(.Platform$OS.type == "windows") {
    dev.int <- c(dev.int, "bmp", "windows", "win.graph", "win.print",
                "win.metafile")
54
    misc.2 <- c(misc.2, "file.choose", "choose.files", "choose.dir",
55 56
    		"setWindowTitle", "loadRconsole",
                "arrangeWindows", "getWindowsHandles")
57 58
}

59 60 61 62
stop.list[["base"]] <-
    if(nchar(Sys.getenv("R_TESTLOTS"))) {## SEVERE TESTING, try almost ALL
	c(edit.int, misc.int)
    } else {
63
	c(inet.list, socket.fun, edit.int, misc.int, misc.2)
64
    }
65
## warning: browseAll will tend to read all the script and/or loop forever
66
stop.list[["methods"]] <- c("browseAll", "recover")
67 68 69
stop.list[["tools"]] <- c("write_PACKAGES", # problems with Packages/PACKAGES
                          "testInstalledBasic",
                          "testInstalledPackages", # runs whole suite
70 71 72 73
                          "readNEWS",              # slow, pure R code
                          "findHTMLlinks", "pskill",
                          "texi2dvi", "texi2pdf"   # hang on Windows
                          )
74
stop.list[["ts"]] <- c("arma0f", "KalmanLike")
75
stop.list[["grDevices"]] <- dev.int
76 77
stop.list[["utils"]] <- c("Rprof", "aspell", # hangs on Windows
                          inet.list, socket.fun, edit.int, misc.int, misc.2)
78 79 80

sink("no-segfault.R")

81 82 83
if(.Platform$OS.type == "unix") cat('options(pager = "cat")\n')
if(.Platform$OS.type == "windows") cat('options(pager = "console")\n')
cat('options(error=expression(NULL))',
84 85
    "# don't stop on error in batch\n##~~~~~~~~~~~~~~\n")

86 87 88 89 90
cat(".proctime00 <- proc.time()\n",
    "c0 <- character(0)\n",
    "l0 <- logical(0)\n",
    "m0 <- matrix(1,0,0)\n",
    "df0 <- as.data.frame(c0)\n", sep="")
91 92 93 94

for (pkg in core.pkgs) {
  cat("### Package ", pkg, "\n",
      "###         ", rep("~",nchar(pkg)), "\n", collapse="", sep="")
95 96 97 98
  pkgname <- paste("package", pkg, sep=":")
  this.pos <- match(paste("package", pkg, sep=":"), search())
  lib.not.loaded <- is.na(this.pos)
  if(lib.not.loaded) {
99
      library(pkg, character = TRUE, warn.conflicts = FALSE)
100
      cat("library(", pkg, ")\n")
101
  }
102
  this.pos <- match(paste("package", pkg, sep=":"), search())
103

104
  for(nm in ls(pkgname)) {
105
      if(!(nm %in% stop.list[[pkg]]) &&
106
	 is.function(f <- get(nm, pos = pkgname))) {
107
	  cat("\n## ", nm, " :\n")
108
	  cat("f <- get(\"",nm,"\", pos = '", pkgname, "')\n", sep="")
109 110 111 112 113 114 115
	  cat("f()\nf(NULL)\nf(,NULL)\nf(NULL,NULL)\n",
	      "f(list())\nf(l0)\nf(c0)\nf(m0)\nf(df0)\nf(FALSE)\n",
	      "f(list(),list())\nf(l0,l0)\nf(c0,c0)\n",
              "f(df0,df0)\nf(FALSE,FALSE)\n",
	      sep="")
      }
  }
116
  if(lib.not.loaded) {
117
      detach(pos=this.pos)
118
      cat("detach(pos=", this.pos, ")\n", sep="")
119 120 121 122 123 124
  }

  cat("\n##__________\n\n")
}

cat("proc.time() - .proctime00\n")