Week 2 revision — R and a first report
Predict the result, explain it, then use R to check. The R reference is available.
Topic quizzes: 6 · 7 · 8 · 9 · 10
1. Assignment is an action when the line runs
You saved growth_mm <- 37 - 20 in a script but did not run it. Must growth_mm now exist in R’s memory? What are its value and units after running?
Saving the script does not run it. After execution, the object contains 17 mm. Restarting removes that session object, while the saved script remains. Run the source from the top to recreate the calculation.
2. Matched values in vectors
For three plants, initial lengths are 20, 22, 19 mm and final lengths are 37, 40, 34 mm. What does position-by-position subtraction assume, and what are the resulting growth values?
Both vectors must refer to the same plants in the same order, with compatible lengths. The growth vector is 17, 18, 15 mm. Its mean is about 16.67 mm. Correct arithmetic on unmatched plants would still answer the wrong question.
3. A table is more than its numbers
The imported seedling table has 24 rows and four columns. What identifies a plant, what units do the length columns use, and why is averaging the plant ID not a meaningful biological summary?
plant_id identifies the plant; the two length columns use millimetres, as specified in the dictionary. IDs label observations rather than measure a quantity, so an average ID has no interpretation. The header names columns and is not another plant. Initial and final lengths in one row belong to one plant.
4. Plot the quantity asked for
For P01, initial length is 25.7 mm and final length is 44.3 mm. Calculate growth. Does a plot with initial length on x and final length on y directly display that growth on its vertical axis?
Growth is 44.3 − 25.7 = 18.6 mm. The first plot’s vertical axis is final size, not change. Create growth_mm = final_mm - initial_mm and plot that derived column when growth is the outcome. Label axes with the actual variables and units, and keep the original CSV unchanged.
5. A report works in the Console but fails when knitted
The error says an object is not found. You created that object interactively before opening the report. What needs repairing, and which files should remain after a successful render?
Put the needed import/calculation into the report before it uses the object, and load its packages there. Keep the .Rmd source, input data, and generated HTML. Render from a fresh session. A Console call to rmarkdown::render() must not be placed inside a report that would then try to render itself.
6. Transfer choice: a fully supplied product calculation
The supplied maximum product mass is 1.00 g; collected dry product is 0.62 g, assumed pure for this simplified task. Percentage yield is 100 × collected mass / maximum mass. What is the yield, and does that number independently establish the product’s purity?
The yield is 62%. The gram units cancel. Purity was an assumption, not a finding from this ratio. Keep the maximum and collected masses as distinct inputs; a larger raw mass is not necessarily a greater percentage when starting scales differ.
7. A stored result becomes stale
After assigning initial_mm <- 20, final_mm <- 37, and growth_mm <- final_mm - initial_mm, you set final_mm <- 39. What is growth_mm before and after rerunning the subtraction?
It remains 17 until the subtraction runs again, then becomes 19 mm. An assigned object holds its stored result; it is not a live spreadsheet formula that automatically recomputes every dependency. Save the correct order in the script and rerun from its inputs.
8. Equal lengths but wrong plants
Initial lengths are c(20,22,19). The correct final vector is c(37,40,34), but a copy has been reordered to c(34,37,40). Both vectors have length three. Is subtraction biologically justified?
Not by equal length alone. R subtracts positions, so the reordered copy gives 14,15,21 mm for incorrect pairs. The correct correspondence gives 17,18,15 mm. Verify identities and order as well as compatible vector lengths.
9. Audit the new input
The transfer study is supplied as 18 independent plants, nine per group. Your report still says 24 plants. Which evidence and source lines should you inspect?
Check the imported filename, project and object; inspect dim(), distinct plant IDs, group labels/counts and missingness. Then check inline and manually written prose against that input. The expected transfer table is 18 by 4 with 18 unique IDs, nine records per group and no missing lengths.
10. A supplied concentration calculation
Amount in mol = mass_g / supplied molar_mass_g_mol; concentration in mmol/L = 1000 × amount / final_volume_l. For 0.2922 g, 58.44 g/mol and 100 mL final volume, what is the result?
100 mL = 0.100 L. The amount is 0.005 mol, giving 0.050 mol/L or 50 mmol/L. Doubling only mass gives 100 mmol/L; doubling only volume gives 25 mmol/L. The quantity refers to final total solution volume, not a solvent volume before addition.
11. An impossible dilution request
The supplied rule is stock volume = target × final volume / stock concentration. A request has stock 100 mmol/L, target 200 mmol/L and final volume 50 mL. What numerical result appears, and why is it not a valid preparation recipe?
The formula gives 100 mL of stock, exceeding the requested 50 mL total. The target is more concentrated than the stock, so dilution by adding solvent alone cannot achieve it. Preserve the row and flag it rather than deleting it or inventing stronger stock.
12. Source, HTML and a revision
You corrected an HTML caption directly, then rendered the R Markdown source again and the correction vanished. Where should the revision live, and what should be tested?
Edit the .Rmd source and render it. The HTML is a generated reading copy and can be replaced. Check the new output location, caption, units, input description and inline counts, then rerender from a fresh session with the required ordinary data files included.
Return to your first report, or continue to data quality.