Search code examples
renvironment-variableshome-directory

How to evoke R home directory in file name construction?


I'm using R under Windows XP. It picked up the environmental variable HOME from windows which is,

> Sys.getenv("R_USER")
R_USER 
"H:" 

However, how can I use that variable quickly in a file name? In particular, if I have a file stored at H:/tmp/data.txt. How should I construct the following command?

data <- read.table("$R_HOME/tmp/data.txt")

That one clearly didn't work.

The only way I got it to work is the following:

data <- read.table(paste(Sys.getenv("R_USER"), "/tmp/data.txt", sep = ""))

Which is so cumbersome that I have to believe there is an easier way. Does anyone know a quick evocation of the HOME variable in R?


Solution

  • Ah, I got it. it's just

    data <- read.table("~/tmp/data.txt")