Week 1 revision — files and computers

Try each question before opening its answer. Use your file manager, terminal, and terminal reference to check actions as well as words.

Topic quizzes: 1 · 2 · 3 · 4 · 5

1. Plain text or not?

You open seedlings.csv, seedlings.xlsx and report.Rmd in Notepad or TextEdit (plain-text mode). Which show readable text, and which file could R read directly as a table?

seedlings.csv and report.Rmd are plain text: only characters, readable in any editor. seedlings.xlsx shows PK and unreadable symbols, because it is a ZIP package of XML files. R reads seedlings.csv directly; that is why the course keeps data as CSV.

2. A relative path needs a starting place

From introcomputing-course, the path data/seedlings.csv works. From inside reports, why does the same path ask for a different location?

A relative path starts at the current folder. From reports it asks for reports/data/seedlings.csv, not the neighbouring data folder. Return to the project root, then locate data/seedlings.csv. The file did not move; your starting location changed. In a shell, use pwd to identify that starting place.

3. Predict a pipe and a saved extract

The supplied samples.tsv has a header plus four records: two control and two treated. The header does not contain treated. What does this print, and does the second command change the source manifest?

grep -F treated samples.tsv | wc -l
grep -F treated samples.tsv > treated-samples.txt

The first command prints a line count of 2. grep sends matching lines through the pipe to wc. The second saves matches to treated-samples.txt; it does not change samples.tsv. > replaces any previous contents of the destination. This is literal text matching, not interpretation of treatment groups or chemical classes. It could also match untreated if that word occurred.

4. Copy, move, and extract

What remains after copying notes.txt to notes-copy.txt? How is moving the original different? Does opening a ZIP preview necessarily mean its files have been extracted into an ordinary project folder?

A copy leaves the original and makes another file. A move changes the original’s location or name. A ZIP preview is a view of an archive; use extraction to create the ordinary folder and files needed for the project. Locate the actual extracted .Rproj, rather than opening one inside an archive preview.

5. A path on someone else’s laptop

Anna’s code reads /Users/anna/Documents/introcomputing-course/data/seedlings.csv. Why does it fail on Ben’s laptop, and which path works for both?

The absolute path contains Anna’s username, so the folder does not exist on Ben’s laptop. The relative path data/seedlings.csv, read from the project folder, works on any computer that has the project.

6. The same filename on two computers

You see report.html in a remote desktop. Is it automatically in your laptop’s Downloads folder? Would a ZIP stored beside the original be a separate backup against losing the laptop?

No to both. Remote access is not automatic file transfer, and identical names can refer to separate copies. Use the supported transfer route and name the destination. A ZIP on the same disk is a convenient sharing package; use supported separate storage for protection against losing that disk.

7. Gene names and Swedish CSV files

A gene list opened and saved in Excel shows 2-Sep where SEPT2 used to be. A classmate’s “CSV” contains P01;control;25,7;44,3. What happened in each case?

Excel turned the gene symbol into a date, and saving made it permanent; about one in five papers with Excel gene lists had such errors (Ziemann et al. 2016). The second file was saved by Excel set to Swedish, which uses semicolons between values and decimal commas. Look at data files in a text editor, and close raw data in a spreadsheet without saving.

8. Two terminal windows

Shell A is inside day03/readings while Shell B is in the workspace root. You run cd .. in Shell A. What changes in Shell B?

Nothing automatically changes in Shell B. Each shell has its own current directory. Check pwd in both windows. The folders themselves did not move, and changing a shell location does not move an independent file-manager window.

9. Quote the intended argument

You want one folder called field notes. Compare mkdir field notes with mkdir “field notes”. Which command expresses the intended single name?

The quoted command groups both words into one argument and creates one named folder. The unquoted command normally supplies two names and creates two folders. Practise only in the disposable workspace, then use ls and the graphical view to inspect what actually exists.

10. A surprising grep count

In a copy of the four-record manifest, S01 is labelled untreated; S03 and S04 are treated. How many records match grep -F treated, and does that count establish three treatment allocations?

There are three literal text matches because untreated contains treated. It does not establish three treated plants. Inspect the selected IDs and use the study description to understand labels. The unchanged source manifest still has two treated records.

11. A manifest path fails

The manifest lists measurements/S04.csv, but the copied folder contains S04-renamed.csv. Should you delete the record, change its measurement, or investigate identity?

Investigate. In the deliberate classroom rename, the file contents still identify S04 and 39.8 mm, and the known rename supports restoring its filename. In a real ambiguous case, obtain source evidence.

12. Console or terminal?

You type pwd in RStudio’s Console and get Error: object 'pwd' not found. Then you type 44.3 - 25.7 in the terminal and get 44.3: command not found. What went wrong, and where does each instruction belong?

Each instruction went to the wrong program. pwd is a shell command and belongs in the terminal, at a $ prompt. 44.3 - 25.7 is R and belongs in the Console, at a > prompt, where it gives 18.6 (P01’s growth in mm). Neither error means the computer is broken.

Return to day 5 exercises to practise in RStudio, or continue to week 2.