| 1 |
####--- Utilities ----------------- |
| 2 |
|
| 3 |
## Was in ./unix/ -- but is called from pdf.end() / ps.end() which are here: ./ps.goodies.R |
| 4 |
Sys.ps.cmd <- function() { |
| 5 |
sys <- (si <- Sys.info())[["sysname"]] |
| 6 |
if(sys == "Linux") { |
| 7 |
s.rel <- si[["release"]] ## 2013-7: Kurt sees s.rel <- "3.9-1-amd64" |
| 8 |
rel <- c(as.integer(strsplit(s.rel,"[[:punct:]]")[[1]][1:2]) %*% c(1000,1)) |
| 9 |
if(is.na(rel)) rel <- 3000 |
| 10 |
if(rel >= 2006) "/bin/ps w" ## Linux kernel >= 2.6 (this is true for Ubuntu!) |
| 11 |
else if(rel >= 2002) "/bin/ps --width 1000" ## Linux >= 2.2 |
| 12 |
else struct("/bin/ps w", type="BSD") |
| 13 |
} |
| 14 |
else if(sys == "SunOS") "/usr/bin/ps" |
| 15 |
else if(sys == "Darwin") { # macOS |
| 16 |
cmd <- struct("/bin/ps w", type="Darwin/macOS") |
| 17 |
## test if it *works* (to some extent) {"sandboxed" did not allow /bin/ps to run} |
| 18 |
tmp <- tryCatch(u.sys(cmd, " | grep 'grep'"), error=identity) |
| 19 |
if(!inherits(tmp, "error")) |
| 20 |
cmd |
| 21 |
else |
| 22 |
stop(cmd," is not working: ", conditionMessage(tmp)) |
| 23 |
} |
| 24 |
else { |
| 25 |
warning("Unknown OS [Operating System]; 'ps' may not be compatible") |
| 26 |
"ps" |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
u.sys <- function(..., intern=TRUE) system(paste0(...), intern=intern) |
| 32 |
|
| 33 |
u.date <- function(short = FALSE) |
| 34 |
format(Sys.time(), paste0("%d/%h/%Y", if(!short) ", %H:%M")) |
| 35 |
## Unix-only: u.sys("date '+%d/%h/%Y", if(!short) ", %H:%M", "'") |
| 36 |
|
| 37 |
u.Datumvonheute <- function(W.tag = 2, Zeit = FALSE) |
| 38 |
{ |
| 39 |
## Ziel: Deutsches (kurzes) Datum (als string) |
| 40 |
## |
| 41 |
## ==> ?u.Datumvonheute [online help] |
| 42 |
## Unix-only: dat <- as.numeric(system("date '+%w %d %m %Y %H %M' | tr ' ' '\n'",TRUE)) |
| 43 |
dat <- as.integer(strsplit(format(Sys.time(),"%w %d %m %Y %H %M"), " ")[[1]]) |
| 44 |
## 1 2 3 4 5 6 |
| 45 |
DMY <- paste0(dat[2], ". ", C.Monatsname[dat[3]], " ", dat[4]) |
| 46 |
r <- if (W.tag) { #-- wollen Wochentag |
| 47 |
W <- ifelse(dat[1]==0, 7, dat[1]) |
| 48 |
if (W.tag==2) Wtag <- C.Wochentag[W] |
| 49 |
else Wtag <- C.Wochentagkurz[W] |
| 50 |
paste(Wtag, DMY, sep=", ") |
| 51 |
} else DMY |
| 52 |
if(Zeit) { |
| 53 |
paste(r, if (Zeit==2) paste(dat[5:6], collapse=":") else dat[5], |
| 54 |
sep="; ") |
| 55 |
} else r |
| 56 |
} |
| 57 |
|
| 58 |
C.Monatsname <- c("Januar", "Februar", "Maerz", "April", "Mai", "Juni", |
| 59 |
"Juli", "August", "September", "Oktober", "November", "Dezember") |
| 60 |
|
| 61 |
C.Wochentag <- c("Montag", "Dienstag", "Mittwoch", "Donnerstag", |
| 62 |
"Freitag", "Samstag", "Sonntag") |
| 63 |
C.Wochentagkurz <- c("Mon", "Die", "Mit", "Don", "Fre", "Sam", "Son") |
| 64 |
|
| 65 |
C.weekday <- c("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun") |
| 66 |
|
| 67 |
## Months: we had |
| 68 |
## C.monthname === month.name in R |
| 69 |
## C.monthshort === month.abb in R |
| 70 |
|
| 71 |
##>>> Please: Forget the following !! it is ===== S function date() !! |
| 72 |
##>>> "u.datum"<- function() unix("date") |
| 73 |
|
| 74 |
u.datumdecode <- |
| 75 |
function(d, YMDHMnames = c("Jahr", "Monat", "Tag", "Std", "Min")) |
| 76 |
{ |
| 77 |
## Ziel: Daten der Form 8710230920 aufspalten in Jahr, Monat, Tag, Std, Min |
| 78 |
## ---------------------------------------------------------------------- |
| 79 |
## Bemerkungen: Dies scheint mir nicht das richtige Konzept. |
| 80 |
## Wenn man numerische Datuemer will, soll man doch julianische |
| 81 |
## Daten verwenden !! Dann hat man auch eine richtige Zeit-Skala |
| 82 |
## Diese Funktionen sind in library(examples) und (verbessert) in |
| 83 |
## /u/maechler/s/date.Data !! (Martin Maechler) |
| 84 |
##======================================================================= |
| 85 |
if(length(YMDHMnames) != 5 || !is.character(YMDHMnames)) |
| 86 |
stop("invalid `YMDHMnames': must be character(5)") |
| 87 |
n <- length(d) |
| 88 |
z <- matrix(NA, n, 5, dimnames = list(names(d), YMDHMnames)) |
| 89 |
for(j in 5:1) { |
| 90 |
h <- d %/% 100 |
| 91 |
z[, j] <- d - 100 * h |
| 92 |
d <- h |
| 93 |
} |
| 94 |
drop(z)# vector if `d' was a scalar (length 1) |
| 95 |
} |