File paths

This section contains some basic tips about file paths.

Remote files vs. local files

If you’re working on the datateam server (RStudio in an internet browser), you’re usually working in the home directory under your username. File paths generally follow this pattern: /home/dmullen/folder/file. Note: These files are not stored on your local machine, they are on a remote server. You can access them through remote SFTP software like Cyberduck.

If you’re working with your local RStudio app then your file paths generally follow this pattern: /Users/datateam/folder/file. These files are stored on your local machine and you can access them with Finder.

File path shortcuts

Using . in a file path refers to your current working directory. You can print your working directory with the call: getwd(). If we assume that my current working directory is home/dmullen, then the following two calls are equivalent:

file.exists('/home/dmullen/myFile.R')
file.exists('./myFile.R')

Using ~ in a file path does not always refer to your current working directory. This is a common misconception. It is actually set to the global R USER path. You can print this with the call: Sys.getenv('USER'). Let’s assume that I’m working on the arcticdatautils package which I open using a .RProj file. This will update my current working directory to: /home/dmullen/arcticdatautils. Now the following calls are equivalent:

file.exists('/home/dmullen/arcticdatautils/myFile.R')
file.exists('~/arcticdatautils/myFile.R')
file.exists('./myFile.R')