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