2

In bash I can do:

BLA=some/directory and then

MyFavoriteFile1=/some/path/to/$BLA/myfile1.someextension
MyFavoriteFile2=/some/path/to/$BLA/myfile2.someextension

I was wondering if the same does exist in R? So that I would only have to change BLA once in the whole script.

1 Answer 1

7

Use file.path:

dir <- file.path("some", "path")
bla <- file.path("some", "directory")
files <- c("file1.R", "file2.exe")

file.path(dir, bla, files)

Produces:

[1] "some/path/some/directory/file1.R"   "some/path/some/directory/file2.exe"

You could also use paste to generically concatenate strings, but file.path makes sure the correct directory separators are used for your OS, etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.