[Rd] OS calls

Prof Brian D Ripley ripley@stats.ox.ac.uk
Wed, 21 Jun 2000 16:16:13 +0100 (BST)


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 seconds

That'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 directory

Look 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 file

Easy: 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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._