burbot
burbot

Reputation: 195

How to use a variable with setwd()?

Example:

var<-"name"
setwd("/media/data/var")

gives an error 'cause directory "/media/data/var" does not exist, but "/media/data/name".

So, how to declare var as variable within a quoted string?

Upvotes: 3

Views: 4402

Answers (1)

Thomas
Thomas

Reputation: 44525

You have to use paste:

setwd(paste0("/media/data/",var))

Or you can use file.path:

setwd(file.path("/media/data",var))

Upvotes: 7

Related Questions