47

Is there a way to get the current windows user name or the windows home within an R session?

Thanks.
(Sorry, if I missed something, but I couldn't find anything)

Sophia
  • 1,821
  • 2
  • 17
  • 19

4 Answers4

60

You can do

Sys.getenv("USERNAME")
Sys.getenv("HOME")

And if you just type

Sys.getenv()

you will see all available environment variables.

flodel
  • 87,577
  • 21
  • 185
  • 223
36

I prefer this

Sys.info()[["user"]]
GSee
  • 48,880
  • 13
  • 125
  • 145
7

If you know how to do it at your system console, the answer would generally be:

system("...that_string...")
IRTFM
  • 258,963
  • 21
  • 364
  • 487
2

If you're looking for the path to the current user's home directory, try:

> dirname("~")
[1] "C:/Users/username
daviewales
  • 2,144
  • 21
  • 30