Locating Files

Data Computing

Where do files live? In trees.

Every file is contained within a directory. Every directory (except root) is contained with another directory.

The path to a file is the sequence of directories between the root and the file.

The path to a file is the sequence of directories between the root and the file.

In this directory tree …

The file path is /Home/Jane/file1

Every file on the computer has a unique identifier consisting of the path and the file name.

A similar idea applies to the files available through the Internet.

The “Working Directory”

Every Rmd file is contained within a directory. This is called the working directory.

Example:

Relative paths are useful because often you will move an entire directory (and it’s contents) to another computer. The absolute path name will probably change. But the relative path remains the same.

Filetype extensions

All computer files are sequences of bits. The software that reads a file interprets the bits according to a specified format. There are different standard formats for different purposes.

Some common filename extensions for the sort of web resources you will be using:

Finding a file path

Most people are used to locating a file by using a file browser.

You click on a directory and then can examine the files and sub-directories contained within that directory.

file.choose(): A handy R function for finding the file path of a file using a file browser:

A typical dialog works like this:

  1. You give the command file.choose() in the R console. (Don’t use file.choose() in an Rmd file.)
  2. You navigate in the familiar way up and down the directories.
  3. You select the file you were looking for.
  4. The file name and (absolute) path of the file are displayed, e.g. /Home/Jane/mydata.csv.
  5. You copy that name into your Rmd file, e.g.

    Cases <- read.csv("/Home/Jane/mydata.csv")

Author: Daniel T. Kaplan