Which House will the Apple be in … ?
Understand the different parts of a computer and how they interact
Navigate through your computer using the command line
Create and delete folders and files
The world will need no more than “about five computers”
Computers take in information or data (INPUT),
crunch it (PROCESSING),
spit out the results (OUTPUT),
and store the data and/or the result (MEMORY).
INPUT: numbered keypad
PROCESSING: convert key presses to cooking time and temperature
MEMORY: clock
OUTPUT: e.g., Cook for 3 minutes at high temperature … DINNER!
$59.99 from Target
Mmm.. dinner
INPUT: keyboard, mouse, scanner, …
PROCESSING & MEMORY: central processing unit (CPU) interprets and executes program instructions, and communicates with input, output, and secondary storage. It has a small amount of temporary memory.
OUTPUT: screen, printer, video, …
SECONDARY STORAGE: hard drives, external drives, flash. These can store large amounts of data and software
Bits of a computer …
Planned, step-by-step instructions.
Two kinds of software:
System software: Operating system (e.g., Windows, MacOS, Unix)
Applications software: Word, Excel, unix programs, .. R!
Operating systems …
do a variety of DIFFERENT things;
INTERACT with the user in COMPLEX ways;
can CHANGE what it does and how it interacts
It manages the computers resources (CPU, memory, drives, outputs)
Establishes a user interface (graphical or command-line)
Executes and provides services for applications software.
You are probably mostly familiar with GRAPHICAL USER interfaces (GUI, “goo-ee”).
GUIs allow users to interact with mouse/finger movements and clicks.
CLI are less user-friendly at first, but much more powerful:
Can keep permanent record of commands
Can automate some/many/all steps by calling this record
All personal computers have GUI and CLI access!
Analagous to a GUI, but for software ‘users’.
Usually an abstraction of underlying specific instructions.
Allows software to work on many/all operating systems.
A file system allows us to access specific data/information on a computer.
Naming is derived from office filing systems for paper documents.
“FILE” = a group of data, e.g., a Word document, R code, image, …
“FOLDER” (or DIRECTORY) = a collection or group of files.
Can be HIERARCHICAL, i.e., allow subfolders.
“PATH” = Full location of a (sub)directory: e.g., “C:\Simon\Teaching\FES720"
It is hierarchical like a postal address:
Simon Queenborough
301 Prospect St
New Haven
CT
USA
“PATH” = Full location of a (sub)directory:
"C:\Simon\Teaching\FES720\"
or file
"C:\Simon\Teaching\FES720\myRfile.txt"
The PATH can be absolute (i.e., it includes the ‘country’ and ‘state’):
"C:\Simon\Teaching\FES720\"
Or, relative to your working directory.
If your working directory is ‘Teaching/’:
"FES720\"
Note: Working with relative paths allows your code to transfer between different computers and users much more easily (we will come back to this).
Relative paths can also be specified using shortcut codes.
So, if the working directoy = C:\Simon\Teaching\FES720\
Path = “.” indicates the current working directory
Path = “.” = C:\Simon\Teaching\FES720\
Path = “..” indicates the directory one level above the current working directory
Path = “..” = C:\Simon\Teaching\
Let’s assume we have the following hierarchical directory stucture:
─ R-project-1
| └─ analysis.r
├─ raw_data
| ├─ 2015
| ├─ 2016
| └─ 2017
├─ processed_data
| └─ data_all_yrs.csv
├─ results
└─ figures
└─ plot1.png
─ R-project-1
| └─ analysis.r
├─ raw_data
| ├─ 2015
| ├─ 2016
| └─ 2017
├─ processed_data
| └─ data_all_yrs.csv
├─ results
└─ figures
└─ plot1.png
Suppose we want to:
Two ways to move around:
bad: use setwd() a lot
good: use relative paths from the main directory (R-project-1/) to read and write
Uniquely identifies a file.
Different OS have different naming conventions and allowed characters.
DRIVE: C:
USER or ROOT: Simon
DIRECTORY: Teaching
SUBDIRECTORY: FES720
FILENAME: myRfile
FILE EXTENSION: .txt
# You will use this function in the lesson
getwd()
# Notice the speech marks/quotation marks:
"C:\Simon\Teaching\FES720\"
R can run in all three OSs, but there are minor differences.
https://www.howtogeek.com/181774/why-windows-uses-backslashes-and-everything-else-uses-forward-slashes/
https://en.wikipedia.org/wiki/Text_file
https://en.wikipedia.org/wiki/Newline
In a GUI, you can create, delete, rename, move, copy, change metadata, etc. files and folders.
You can do the same in a CLI.
Zen and the Art of File and Folder Organization
Updated: 2018-09-30