I've just been reviewing some functions in my syskern library. This library was set up originally to provide me with a way to program around small R/S differences and to encapsulate some operating system requests in one place, so that these problems would not be spread throughout my code. Over the years the need for many of the programs in this library has disappeared. I have always worked in Unix but my hope was that other R users would implement the operating system functions for other OSs. To some extent this has happened, in the sense that many functions I once had in syskern are now handled in Rbase. Most of the remaining functions are rather trivial or small variations on things already done in Rbase, and I think it would be valuable for everyone if these too could be added to Rbase. The most difficult of the functions is probably mail, but that is already being done in bug.report(), so I am only suggesting that it should be separated out of bug.report() and provided as a separate function. Below are my Unix implementations of remaining OS utilities. Paul Gilbert _______ sleep <- function(n) {system.call(paste("sleep ", n))} # pause for n seconds present.working.directory <- function(){system.call("pwd")} #present directory local.host.netname <- function() {system.call("uname -n")} whoami <- function(){system.call("whoami")} # return user id (for mail) # There are problems with different shells returning different results for whoami when # a user does su to another name. It is probably better to use a C call for this. file.copy <- function(from, to)system.call(paste("cp ", from, to)) #copy file file.date.info <- function(file.name) {# This could be a lot better. It will fail for files older than a year. # Also, a returned format like date() below would be better. mo <- (1:12)[c("Jan","Feb","Mar","Apr","May", "Jun","Jul","Aug", "Sep", "Oct","Nov","Dec") = substring(system.call(paste("ls -l ",file)),33,35)] day <- as.integer(substring(system.call(paste("ls -l ",file.name)),37,38)) hr <- as.integer(substring(system.call(paste("ls -l ",file.name)),40,41)) sec <- as.integer(substring(system.call(paste("ls -l ",file.name)),43,44)) c(mo,day,hr,sec) } # Except for tz this could use the date() function in R, but that may not be the best way. date.parsed <- function() {d<-parse(text=strsplit( system.call("date \'+%Y %m %d %H %M %S\'")," ")[[1]]) list(y= eval(d[1]), m=eval(d[2]), d= eval(d[3]), H= eval(d[4]), M= eval(d[5]), S= eval(d[6]), tz=system.call("date '+%Z'")) } mail <- function(to, subject="", text="") {# If to is null then mail is not sent (useful for testing). file <- tempfile() write(text, file=file) if(!is.null(to)) system.call(paste("cat ",file, " | mail -s '", subject, "' ", to)) unlink(file) invisible() } -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 21 Jun 2000, Paul Gilbert wrote:> I've just been reviewing some functions in my syskern library. This library was > set up originally to provide me with a way to program around small R/S > differences and to encapsulate some operating system requests in one place, so > that these problems would not be spread throughout my code. Over the years the > need for many of the programs in this library has disappeared. > > I have always worked in Unix but my hope was that other R users would implement > the operating system functions for other OSs. To some extent this has happened, > in the sense that many functions I once had in syskern are now handled in Rbase. > Most of the remaining functions are rather trivial or small variations on things > already done in Rbase, and I think it would be valuable for everyone if these > too could be added to Rbase. The most difficult of the functions is probably > mail, but that is already being done in bug.report(), so I am only suggesting > that it should be separated out of bug.report() and provided as a separate > function. > > Below are my Unix implementations of remaining OS utilities. > > Paul Gilbert > _______ > > sleep <- function(n) {system.call(paste("sleep ", n))} # pause for n secondsThat's on my TODO list (but allowing sub-sec accuracy). KH suggested that we hide names like that behind a .Sys call (but then he introduced getwd). There is already at least one object called sleep (a dataset) in an R package.> present.working.directory <- function(){system.call("pwd")} #present directoryLook at getwd!> local.host.netname <- function() {system.call("uname -n")} > whoami <- function(){system.call("whoami")} # return user id (for mail) > # There are problems with different shells returning different results for > whoami when > # a user does su to another name. It is probably better to use a C call > for this.Those are not even meaningful on vanilla (non-networked) Windows systems. I am not really sure why one would want them in general R code.> file.copy <- function(from, to)system.call(paste("cp ", from, to)) #copy fileEasy: use file.create and file.append. -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Brian>> local.host.netname <- function() {system.call("uname -n")} >> whoami <- function(){system.call("whoami")} # return user id (for mail)>Those are not even meaningful on vanilla (non-networked) Windows systems. I >am not really sure why one would want them in general R code.I thought whoami was meanful on Windows NT even without a network, but in any case it is true that I want it for a network environment. You could put in somewhat meaningful defaults like "localhost" and "root", but I think most people are on a network these days. Thanks for pointing out some of the other things that are already working. Paul -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 21 Jun 2000, Paul Gilbert wrote:> Brian > > >> local.host.netname <- function() {system.call("uname -n")} > >> whoami <- function(){system.call("whoami")} # return user id (for mail) > > >Those are not even meaningful on vanilla (non-networked) Windows systems. I > >am not really sure why one would want them in general R code. > > I thought whoami was meanful on Windows NT even without a network, but in anyNT, yes, Win 9x, no, and Win 9x is > 90% of the market.> case it is true that I want it for a network environment. You could put in > somewhat meaningful defaults like "localhost" and "root", but I think most > people are on a network these days.I doubt it. DUN does not count as a network for these purposes, and indeed the local and network IDs can be different even on NT (and frequently are). -- Brian D. Ripley, ripley@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._