File paths in statistical software

A short thread (PSA) on a FOC (frequently occurring problem) that shouldn’t be one: file paths in statistical software.

Comment in a recent reply to one of our replication reports (note: this was not actually a problem):

“We use a HPC and a Linux environment. Therefore, the folders are separated by / and not \ . This might create problems if working with Windows.”

Actually, it does not!

Stata

Every Stata user (but in particular those on Windows) should know 👇. Rule: ALWAYS use “/”, NEVER “\” and you should be fine.

Stata note on paths

R

use “file.path('path','file')” or even use packages here or rprojroot.

Matlab

Use “/” and it will do the right thing.

Matlab paths

Python

os.path.join() is your friend

Python paths

Others

And there are likely similar functions in lots of other programming languages and statistical software.

Take away

Be aware of and always use the platform independent coding of paths, either a function or using “/”. NEVER use “\”.




Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • On the Dangers of Online Storage
  • On the use of Excel for reproducible tables
  • How to respond to data provider requests for data removal (take-down requests)
  • On the use and reuse of within-project code
  • On the use and redistribution of data