1## .onLoad <- function(lib, pkg)
2## {
3
4## }
5
6##' return 'x' unless it is NULL where you'd use 'orElse'
7`%||%` <- function(x, orElse) if(!is.null(x)) x else orElse
8
9
10## if(!exists("rep_len", mode = "function")) # old R version
11##     rep_len <- function(x, length.out) rep(x, length.out=length.out)
12
13if(getRversion() < "3.5") {
14## if(!is.function(.BaseNamespaceEnv$...length)) # ...length() only in R >= 3.5.0
15    ## This substitute is kludgy  by using parent.env() -- but it works (sometimes)
16    ## in funEnv() -- see ../R/misc-goodies.R
17    ...length <- function() eval(quote(length(list(...))), envir = parent.frame())
18
19    isTRUE  <- function(x) is.logical(x) && length(x) == 1L && !is.na(x) && x
20    isFALSE <- function(x) is.logical(x) && length(x) == 1L && !is.na(x) && !x
21}
22
23.set.eps_view <- function() {
24    ## This assumes  "gv"  in your path --- ideally this would be configured!
25    if(!is.character(getOption("eps_view")) && .Platform $ OS.type == "unix") {
26	SYS <- function(cmd) system(cmd, intern=TRUE, ignore.stderr=TRUE)
27        ## doesRespond <- function(cmd) length(SYS(cmd)) > 0
28        doesRespond <- function(cmd) ## should be portable (thanks BDR):
29            all(system(paste(cmd,"> /dev/null")) != c(1,256)*127)
30	if(doesRespond("gv -h")) { ## 'gv'
31	    cmd <- "gv -watch -geometry -0+0 -magstep -2 -media BBox -noantialias"
32	    hyphens <-
33		SYS(paste("gv -h | fgrep watch | head -1",
34			  "| sed 's/watch.*//; s/^[\\s ]*//'"))
35	    if(length(hyphens) && hyphens == "--")
36		cmd <- sub(" --geometry", " -geometry",
37			   sub(" --magstep ", " --scale=",
38			       sub(" --media ", " --media=",
39				   gsub(" -([a-z])", " --\\1", cmd))))
40	}
41	else if (doesRespond("ggv --version")) { ## try 'ggv'
42	    cmd <- "ggv --geometry -0+0"
43	} else if (doesRespond("evince --version")) { ## try 'evince'
44	    cmd <- "evince" # no geometry options
45	} else if (doesRespond("kghostview --version")) { ## try 'kghostview'
46	    cmd <- "kghostview --geometry -0+0"
47	} else {
48	    warning("no valid postscript previewer found; consider setting\n",
49		    "  options(\"eps_view\"=  \"....\")	    yourself")
50	    cmd <- "replace_with_postscript_previewer"
51	}
52	options("eps_view" = cmd)
53    }
54}
55