40

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,721
  • 2
  • 16
  • 19

4 Answers4

49

You can do

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

And if you just type

Sys.getenv()

you will see all available environment variables.

flodel
  • 85,263
  • 19
  • 176
  • 215
32

I prefer this

Sys.info()[["user"]]
GSee
  • 47,140
  • 13
  • 121
  • 142
7

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

system("...that_string...")
IRTFM
  • 251,731
  • 20
  • 347
  • 472
1

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

> dirname("~")
[1] "C:/Users/username
daviewales
  • 1,886
  • 18
  • 28