views:

47

answers:

1

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. So if you know a quick evocation of the HOME variable in R, please let me know!

A: 

Ah, I got it. it's just

data <- read.table("~/tmp/data.txt")
Zhang18
See `?file.path` for a more general method of constructing file paths, e.g., `file.path("~", "tmp", "data.txt")`.
Richie Cotton