Dan
Dan

Reputation: 951

How to substitute variable in file path

I know nothing about R, but would like to know to substitute a variable that could be used to replace the /home/subdirectory/DataFiles/ in the following (snippet) of R code:

x1 <- subset(read.csv("/home/subdirectory/DataFiles/Isic_bilateral_trade1.csv"),
             year>=1990)

Upvotes: 2

Views: 3917

Answers (1)

Jesse Anderson
Jesse Anderson

Reputation: 4603

Set the directory as a variable and use the file.path method:

dataDir <- "/home/subdirectory/DataFiles"
x1 <- subset(read.csv(file.path(dataDir, "Isic_bilateral_trade1.csv")),year>=1990)

etc.

Upvotes: 2

Related Questions