[R] getting a windows environment variable in r

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Oct 12 18:34:05 CEST 2000

> Date: Thu, 12 Oct 2000 08:38:17 -0700
> From: "Bob Sandefur" <rls at pincock.com>
> hi-
>  I would like to get a value set with the dos set command (e.g. set dog=cow) 
in a rterm session on rterm 1011 under windows 2000. if I try in a dos window:

I didn't know Windows 2000 contained dos (NT4 does not), and suspect
you mean a cmd.exe window.  Given that level of confusion, I can see
why you have not read the R documentation for system() correctly.

> set dog=cow
> echo %dog%
> i get cow (what I want)
> then i start rterm
> system("echo %dog%",intern=T)
> gives "%dog%"

That is what it is supposed to do.  Do re-read the documentation for
system().  You probably meant to use shell(), as system does not run a
shell and you have given a cmd.exe internal command.

> I can of course do something like
> set dog=cow
> echo  %dog% >jnk.rin
> and  then start rterm and
> jnk<-read.table("jnk.rin")
> wantthis<-as.character(V1[1])
> wantthis now has what I want
> Are there simpler methods?

Probably. You can read any environment variable in R by getenv()
(Sys.getenv from the next version).  It's just that I don't know if the
`set' you use creates an environment variable, but it probably does
(and you are assuming that it does as to be able to pass it on from the
cmd.exe shell).  In tcsh (which is what I use)

setenv dog cow

and anywhere you can use

rterm dog=cow

Brian D. Ripley,                  ripley at 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-help 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-help-request at stat.math.ethz.ch

More information about the R-help mailing list