Day 24 — Reproduce and share your report
Lecture slides · Quiz · Weekly revision
Can someone else get the same report?
Your supervisor, a lab partner, or you next year should be able to open your project and get exactly the same report. Today you find out whether that works: you render the report from a fresh R session, pack the project into a ZIP, and open it as the receiver would, in a new place.
Use the report from day 23. The examples use the duckweed study (duckweed-report.Rmd and data/duckweed.csv; design in data/README.md): 20 flasks, 10 per group, with F17 spilled before weighing. For the organic alternative, substitute organic-study.Rmd and data/organic-recovery.csv throughout.
Save today: the corrected report and its HTML, a tested report-share-v2.zip, algae-brief.Rmd with its HTML, and reports/reproduction-log.txt, where you note what you tested and what you found.
Does the report tell a reader what they need?
Read your report as someone who was not in the room, and use it to find out whether the nutrient flasks grew more. A reader should be able to find the question, that each flask is one independent unit, why there are 9 nutrient values and not 10 (F17), the units, which group is subtracted from which, and your conclusion. They should also be able to tell SD (spread among flasks) from the confidence interval (uncertainty in the difference). The numbers to expect: 10 control flasks with mean biomass 32.28 mg and 9 nutrient flasks with 39.63 mg.
Replace any leftover notes such as “insert result here” with your interpretation.
Does it render from a fresh R session?
Save the .Rmd, choose Session → Restart R, and click Knit without running anything in the Console first. Restarting empties R’s memory, so the report must now import, calculate and plot everything itself, just as it will on someone else’s computer. If rendering stops, read the first error and the chunk it names, and fix one thing at a time:
| Error | Usual cause | Repair |
|---|---|---|
object 'duckweed' not found |
The import was only run in the Console | Put the import in a chunk before it is used |
could not find function |
A package was only loaded in the Console | Add its library() call to the setup chunk |
cannot open file |
A personal path such as C:/Users/…, or a missing file |
Use data/duckweed.csv and keep that file in the project |
| Old text disagrees with new numbers | A result was typed by hand | Check the sentence, or use an inline result |
Packing the project as a ZIP
A ZIP is one file that holds a whole folder, which makes it the simplest way to hand a project to someone or to submit it. First make the folder complete, then pack it.
Use the file manager to create report-share outside your working project, for example in Documents, and copy in:
report-share/
├── introcomputing.Rproj
├── duckweed-report.Rmd
├── duckweed-report.html
├── README.txt
├── data/
│ ├── duckweed.csv
│ └── README.md
└── output/
└── README.txt
The .Rmd and the CSV are the analysis; the HTML lets someone read the result without R; data/README.md describes the study. Include output/ if your report saves a figure there. In README.txt, write that the data are simulated, which file to render, the packages it needs (readr, dplyr, ggplot2, rmarkdown, knitr), and what one row of the CSV is.
Then, in a shell, go to the folder that contains report-share and pack it:
zip -r report-share-v1.zip report-share/
unzip -l report-share-v1.zip-r packs the folder with everything inside it, and unzip -l lists what went in: check that the .Rmd, data/duckweed.csv and the README are there. The ZIP is saved beside report-share, not inside it; a ZIP inside the folder it packs would pack an old copy of itself next time. Give every new ZIP a new name (-v1, -v2): re-running zip on an existing name updates it and can keep files you have since deleted.
Copy report-share into your Ubuntu workspace with File Explorer before running zip. The Windows and Ubuntu copies are separate and do not update each other, so after any edit in Windows, copy again before zipping. Copy the finished ZIP back to a normal Windows folder before the receiver test below, because RStudio runs in Windows.
Does it work in a new location?
Listing the ZIP shows names, not whether the report works. Extract it into a new, empty folder, as the receiver would, and use it to find out whether the report comes out the same:
unzip report-share-v1.zip -d receiver-v1
ls receiver-v1ls shows only report-share: extraction keeps the packed folder, so it adds one level, and the report is at receiver-v1/report-share/duckweed-report.Rmd. Open receiver-v1/report-share/introcomputing.Rproj (the project name in RStudio’s corner tells you which copy you are in), restart R and Knit.
You should see the same counts (10 and 9 flasks), the same means (32.28 and 39.63 mg) and the same conclusion. Point positions in a jittered plot may shift slightly between computers. If numbers differ, record sessionInfo() in your log: it lists the R and package versions.
Look at the actual extracted folder tree. The .Rproj file does not contain any data, and a shortcut to your original data folder does not travel with the ZIP. Copy the CSV itself into report-share/data/ and pack again under a new name.
Correcting a ZIP you already made
Your receiver test will probably show something to improve, such as a unit missing from the README. A ZIP is a snapshot of the folder at the moment you made it, so use this correction to find out what happens to the copies you already have.
- Edit
README.txtin your ordinaryreport-sharefolder, for example by adding “Biomass is dry mass in mg per flask.” - Open
receiver-v1/report-share/README.txt. It still has the old text, and so doesreport-share-v1.zip. - Pack again as
report-share-v2.zip, extract it toreceiver-v2, and check that the new sentence is really there. Add one line to the README saying what changed in v2.
A ZIP on the same laptop as the original is a way of sharing, not a backup: if the laptop is lost, both are gone. Put a copy of the finished project on the supported separate storage as well, and write in your log where it is.
What does a successful render tell you?
Use two disposable copies of report-share to find out which mistakes stop a report and which do not.
- In the first copy, rename
data/duckweed.csvtoduckweed-missing.csv, restart R and Knit. Rendering stops with an error naming the file, because the report can no longer find its input. Restore the name and check that the means are back to 32.28 and 39.63 mg. - In the second copy, replace your sentence about F17 with “All 20 flasks had a measured biomass.” and Knit. The report renders without complaint, although the sentence contradicts the data: only 19 flasks were weighed. (Organic route: “The percentage yield shows that the product is pure.”)
R can tell you that a file is missing, but not that a sentence is wrong. A report that renders still needs a reader who checks its claims against the numbers. Note both cases in your log, and delete the disposable copies so the false sentence cannot end up in what you share.
A second report: the algae memo
On day 23 you analysed data/algae.csv in algae-transfer.R: 24 cultures, 12 per group, with A19’s biomass missing. Turn it into a small report and use the same steps to find out whether it reproduces.
- Create
algae-brief.Rmdat the project root with a short question, the import, the group summary, one plot of individual cultures, and a sentence on the missing A19. Use inline R for the counts, so they come from the data. - Restart R and Knit. You should see 12 reference cultures with mean 28.20 mg and 11 supplement cultures with mean 33.92 mg.
- Pack
algae-share(the.Rproj,algae-brief.Rmd, its HTML,data/algae.csv,data/README.mdand a README) asalgae-share-v1.zip, extract it into a new folder, and Knit there. The counts and means should match step 2. If they do not, compare the input and code before suspecting rounding: 33.91818 and 33.92 are the same mean, 34.32 would be a different one.
Check your understanding
It may use objects created only in the Console, a personal file path, or files that are not in the ZIP. Restarting R and rendering in a new folder finds these.
report-share-v1.zip. Does v1 contain the fix?
No. A ZIP is a snapshot. Make a newly named ZIP, extract it into a new folder, and check the fix there.
No. If the disk is lost, the ZIP is lost with it. Keep a copy on separate supported storage.
It shows that the saved source and data make the same report on this computer. Whether the design and conclusion are sound is a separate question for the reader.