| 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 |
|
| 13 |
## For backwards compatibility with earlier versions of R, |
| 14 |
## at least until x.y.z if we have Depends: R (>= x.y.z) |
| 15 |
if((Rv <- getRversion()) < "4.1.0") { |
| 16 |
if(## Namespace not locked yet, but being defensive here: |
| 17 |
!environmentIsLocked(Mns <- parent.env(environment()))) { |
| 18 |
assign("...names", envir = Mns, inherits = FALSE, |
| 19 |
function() eval(quote(names(list(...))), sys.frame(-1L))) |
| 20 |
} |
| 21 |
|
| 22 |
if(Rv < "4.0.0") { |
| 23 |
deparse1 <- function (expr, collapse = " ", width.cutoff = 500L, ...) |
| 24 |
paste(deparse(expr, width.cutoff, ...), collapse = collapse) |
| 25 |
|
| 26 |
if(Rv < "3.5") { |
| 27 |
## if(!is.function(.BaseNamespaceEnv$...length)) # ...length() only in R >= 3.5.0 |
| 28 |
## This substitute is kludgy by using parent.env() -- but it works (sometimes) |
| 29 |
## in funEnv() -- see ../R/misc-goodies.R |
| 30 |
...length <- function() eval(quote(length(list(...))), envir = parent.frame()) |
| 31 |
|
| 32 |
isTRUE <- function(x) is.logical(x) && length(x) == 1L && !is.na(x) && x |
| 33 |
isFALSE <- function(x) is.logical(x) && length(x) == 1L && !is.na(x) && !x |
| 34 |
} |
| 35 |
|
| 36 |
}## Rv < 4.0.0 |
| 37 |
|
| 38 |
}## Rv < 4.1.0 |
| 39 |
|
| 40 |
.set.eps_view <- function() { |
| 41 |
## This assumes "gv" in your path --- ideally this would be configured! |
| 42 |
if(!is.character(getOption("eps_view")) && .Platform $ OS.type == "unix") { |
| 43 |
SYS <- function(cmd) system(cmd, intern=TRUE, ignore.stderr=TRUE) |
| 44 |
## doesRespond <- function(cmd) length(SYS(cmd)) > 0 |
| 45 |
doesRespond <- function(cmd) ## should be portable (thanks BDR): |
| 46 |
all(system(paste(cmd,"> /dev/null")) != c(1,256)*127) |
| 47 |
if(doesRespond("gv -h")) { ## 'gv' |
| 48 |
cmd <- "gv -watch -geometry -0+0 -magstep -2 -media BBox -noantialias" |
| 49 |
hyphens <- |
| 50 |
SYS(paste("gv -h | fgrep watch | head -1", |
| 51 |
"| sed 's/watch.*//; s/^[\\s ]*//'")) |
| 52 |
if(length(hyphens) && hyphens == "--") |
| 53 |
cmd <- sub(" --geometry", " -geometry", |
| 54 |
sub(" --magstep ", " --scale=", |
| 55 |
sub(" --media ", " --media=", |
| 56 |
gsub(" -([a-z])", " --\\1", cmd)))) |
| 57 |
} |
| 58 |
else if (doesRespond("ggv --version")) { ## try 'ggv' |
| 59 |
cmd <- "ggv --geometry -0+0" |
| 60 |
} else if (doesRespond("evince --version")) { ## try 'evince' |
| 61 |
cmd <- "evince" # no geometry options |
| 62 |
} else if (doesRespond("kghostview --version")) { ## try 'kghostview' |
| 63 |
cmd <- "kghostview --geometry -0+0" |
| 64 |
} else { |
| 65 |
warning("no valid postscript previewer found; consider setting\n", |
| 66 |
" options(\"eps_view\"= \"....\") yourself") |
| 67 |
cmd <- "replace_with_postscript_previewer" |
| 68 |
} |
| 69 |
options("eps_view" = cmd) |
| 70 |
} |
| 71 |
} |