Re: [R] Get home directory and simple I/O

2007-03-23 Thread Andris Jankevics
If you want get a username of user currently running R on Linux,you can use a 
system command and read enviroment variables:

paste(/home/,system (whoami,intern=TRUE),sep=)


Andris Jankevics

On Piektdiena, 23. Marts 2007 14:30, Alberto Monteiro wrote:
 Is there any generic function that gets the home directory? This
 should return /home/user in Linux and
 x:/Documents and Settings/user (or whatever) in Windows XP.

 Another (unrelated) question: what is the _simplest_ way to
 read and write R variables to/from files such that they are
 stored in a human-readable but R-like form? For example, if
 (say), x is a vector defined as x - c(1, 2, 3), can I write
 (and read) x as a file with just one line, namely: c(1, 2, 3) ?

 Alberto Monteiro

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html and provide commented, minimal,
 self-contained, reproducible code.

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Get home directory and simple I/O

2007-03-23 Thread Henrik Andersson
Sys.getenv(HOME) works in Linux at least

- Henrik

Andris Jankevics wrote:
 If you want get a username of user currently running R on Linux,you can use a 
 system command and read enviroment variables:

 paste(/home/,system (whoami,intern=TRUE),sep=)


 Andris Jankevics

 On Piektdiena, 23. Marts 2007 14:30, Alberto Monteiro wrote:
   
 Is there any generic function that gets the home directory? This
 should return /home/user in Linux and
 x:/Documents and Settings/user (or whatever) in Windows XP.

 Another (unrelated) question: what is the _simplest_ way to
 read and write R variables to/from files such that they are
 stored in a human-readable but R-like form? For example, if
 (say), x is a vector defined as x - c(1, 2, 3), can I write
 (and read) x as a file with just one line, namely: c(1, 2, 3) ?

 Alberto Monteiro

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html and provide commented, minimal,
 self-contained, reproducible code.
 

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
   


-- 
Henrik Andersson

Danish Meteorological Institute
Lyngbyvej 100
2100 Copenhagen Ø
Denmark
Tel: +45 39157215 
Email: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Get home directory and simple I/O

2007-03-23 Thread jim holtman
On 3/23/07, Alberto Monteiro [EMAIL PROTECTED] wrote:

 Is there any generic function that gets the home directory? This
 should return /home/user in Linux and
 x:/Documents and Settings/user (or whatever) in Windows XP.

 Another (unrelated) question: what is the _simplest_ way to
 read and write R variables to/from files such that they are
 stored in a human-readable but R-like form? For example, if
 (say), x is a vector defined as x - c(1, 2, 3), can I write
 (and read) x as a file with just one line, namely: c(1, 2, 3) ?


?dput

Alberto Monteiro

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Get home directory and simple I/O

2007-03-23 Thread Gabor Grothendieck
See:

?R.home
?dput

On 3/23/07, Alberto Monteiro [EMAIL PROTECTED] wrote:
 Is there any generic function that gets the home directory? This
 should return /home/user in Linux and
 x:/Documents and Settings/user (or whatever) in Windows XP.

 Another (unrelated) question: what is the _simplest_ way to
 read and write R variables to/from files such that they are
 stored in a human-readable but R-like form? For example, if
 (say), x is a vector defined as x - c(1, 2, 3), can I write
 (and read) x as a file with just one line, namely: c(1, 2, 3) ?

 Alberto Monteiro

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Get home directory and simple I/O

2007-03-23 Thread Liaw, Andy
From: Gabor Grothendieck
 
 See:
 
 ?R.home

That's not what Alberto wanted:  It gives the location of the R
installation, not where user's home directory is.  AFAIK Windows does
not set the HOME environment variable by default.

 ?dput
 
 On 3/23/07, Alberto Monteiro [EMAIL PROTECTED] wrote:
  Is there any generic function that gets the home directory? This 
  should return /home/user in Linux and x:/Documents and 
  Settings/user (or whatever) in Windows XP.
 
  Another (unrelated) question: what is the _simplest_ way to 
 read and 
  write R variables to/from files such that they are stored in a 
  human-readable but R-like form? For example, if (say), x is 
 a vector 
  defined as x - c(1, 2, 3), can I write (and read) x as a file with 
  just one line, namely: c(1, 2, 3) ?
 
  Alberto Monteiro
 
  __
  R-help@stat.math.ethz.ch mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide 
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
 
 
 


--
Notice:  This e-mail message, together with any attachments,...{{dropped}}

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Get home directory and simple I/O

2007-03-23 Thread Prof Brian Ripley
But the request was for a *generic* solution.  On Windows there
might not be anything corresponding to a home directory (and the rw-FAQ 
discusses the concept and how R resolves this).

The best answer I know of is path.expand(~).

On Fri, 23 Mar 2007, Henrik Andersson wrote:

 Sys.getenv(HOME) works in Linux at least

But not all Unix shells have it set, and a user can unset or reset it.  To 
be perverse:

gannet% unsetenv HOME
gannet% R --slave
Sys.getenv(HOME)
HOME
   
path.expand(~)
[1] /data/gannet/ripley
q()

(If you set HOME to something other than your home directory it will be 
honoured.)


 - Henrik

 Andris Jankevics wrote:
 If you want get a username of user currently running R on Linux,you can use a
 system command and read enviroment variables:

 paste(/home/,system (whoami,intern=TRUE),sep=)

And my home directory is not '/home/ripley' on any of the Linux boxes I 
use (even though it exists on some of them), e.g. on my compute server

 path.expand(~)
[1] /data/gannet/ripley

and on our main cluster

 path.expand(~)
[1] /home/markov/ripley


 Andris Jankevics

 On Piektdiena, 23. Marts 2007 14:30, Alberto Monteiro wrote:

 Is there any generic function that gets the home directory? This
 should return /home/user in Linux and
 x:/Documents and Settings/user (or whatever) in Windows XP.

[...]

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
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 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Get home directory and simple I/O

2007-03-23 Thread Gabor Grothendieck
On 3/23/07, Liaw, Andy [EMAIL PROTECTED] wrote:
 From: Gabor Grothendieck
 
  See:
 
  ?R.home

 That's not what Alberto wanted:  It gives the location of the R
 installation, not where user's home directory is.  AFAIK Windows does
 not set the HOME environment variable by default.

ok.  Try this, at least on Windows XP:

paste(Sys.getenv(c(HOMEDRIVE, HOMEPATH)), collapse = )

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Get home directory and simple I/O

2007-03-23 Thread Gabor Grothendieck
path.expand(~) also seems to work on Windows XP.

On 3/23/07, Prof Brian Ripley [EMAIL PROTECTED] wrote:
 But the request was for a *generic* solution.  On Windows there
 might not be anything corresponding to a home directory (and the rw-FAQ
 discusses the concept and how R resolves this).

 The best answer I know of is path.expand(~).

 On Fri, 23 Mar 2007, Henrik Andersson wrote:

  Sys.getenv(HOME) works in Linux at least

 But not all Unix shells have it set, and a user can unset or reset it.  To
 be perverse:

 gannet% unsetenv HOME
 gannet% R --slave
 Sys.getenv(HOME)
 HOME
   
 path.expand(~)
 [1] /data/gannet/ripley
 q()

 (If you set HOME to something other than your home directory it will be
 honoured.)

 
  - Henrik
 
  Andris Jankevics wrote:
  If you want get a username of user currently running R on Linux,you can 
  use a
  system command and read enviroment variables:
 
  paste(/home/,system (whoami,intern=TRUE),sep=)

 And my home directory is not '/home/ripley' on any of the Linux boxes I
 use (even though it exists on some of them), e.g. on my compute server

  path.expand(~)
 [1] /data/gannet/ripley

 and on our main cluster

  path.expand(~)
 [1] /home/markov/ripley


  Andris Jankevics
 
  On Piektdiena, 23. Marts 2007 14:30, Alberto Monteiro wrote:
 
  Is there any generic function that gets the home directory? This
  should return /home/user in Linux and
  x:/Documents and Settings/user (or whatever) in Windows XP.

 [...]

 --
 Brian D. Ripley,  [EMAIL PROTECTED]
 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 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Get home directory and simple I/O

2007-03-23 Thread Alberto Monteiro
Prof Brian Ripley wrote:

 But the request was for a *generic* solution.  On Windows there
 might not be anything corresponding to a home directory
 (and the rw-FAQ discusses the concept and how R resolves this).
 
 The best answer I know of is path.expand(~).
 
Thanks, this is the only solution that works for Windows XP,
and it will probably work for Linux.

Also, in Windows, there are variables homedrive and homepath,
that I could combine to form the path (probably this is what
path.expand does :-))

Sys.getenv(homepath)
Sys.getenv(homedrive)

Alberto Monteiro

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Get home directory and simple I/O

2007-03-23 Thread Peter Dalgaard
Andris Jankevics wrote:
 If you want get a username of user currently running R on Linux,you can use a 
 system command and read enviroment variables:

 paste(/home/,system (whoami,intern=TRUE),sep=)

   
This would be more to the point (and safer), I think.

  Sys.getenv(HOME)
HOME
/home/bs/pd


 Andris Jankevics

 On Piektdiena, 23. Marts 2007 14:30, Alberto Monteiro wrote:
   
 Is there any generic function that gets the home directory? This
 should return /home/user in Linux and
 x:/Documents and Settings/user (or whatever) in Windows XP.

 Another (unrelated) question: what is the _simplest_ way to
 read and write R variables to/from files such that they are
 stored in a human-readable but R-like form? For example, if
 (say), x is a vector defined as x - c(1, 2, 3), can I write
 (and read) x as a file with just one line, namely: c(1, 2, 3) ?

 Alberto Monteiro

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html and provide commented, minimal,
 self-contained, reproducible code.
 

 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.