Vasily A
Vasily A

Reputation: 8646

Get windows system folders (user home directory, "My documents", etc) path in R

I would like to get the full path of user's home folder (usually something like C:\Users\%USERNAME%) or "My documents" folder and can't find the way to do this from R script. Is there any solution for this?

Upvotes: 18

Views: 7391

Answers (3)

Guilherme S Mohor
Guilherme S Mohor

Reputation: 53

To get C:/Users/%USERNAME% without any extra package (or, with "base") you can use

Sys.getenv("USERPROFILE")

The path.expand('~') suggested above gave me the equivalent of C:/Users/%USERNAME%/Documents

obs: that worked for me in Win 10 and Win11 and with R3.4 and 4.1

Upvotes: 4

Lisa B.
Lisa B.

Reputation: 255

With the package fs, you can also get the home directory:

library(fs)

path_home()

Upvotes: 3

Jthorpe
Jthorpe

Reputation: 10194

I think you want:

path.expand('~')

Upvotes: 34

Related Questions