Communicating
Limitations in R
Learn to identify and clearly express the tradeoffs in your R code: when to prioritize readability over performance, and how to document every decision so others can follow your reasoning.
What Are Limitations?
Every piece of code you write comes with limitations: constraints on what it can do, how fast it runs, and how easy it is for another person to understand. A limitation is not a flaw: it is a deliberate boundary you chose (or accepted) when writing your solution.
Why Communicate Them?
The Core Tradeoff: Readability vs Performance
As you optimize R code for performance, readability often drops. The goal is to find a sweet spot where both are acceptable, and to document why you chose that point.
What Makes Code Readable?
What Makes Code Performant?
Readable vs Performant: Side by Side
The Tradeoff Spectrum
Most school and data-analysis R projects should sit on the left to center of this spectrum. Only move right when profiling reveals a real bottleneck.
How to Communicate Limitations
Example 1: Simple Comment
Example 2: Function Documentation
Example 3: README Documentation
Types of Limitations
When Should You Optimize?
Common Mistakes
Summary Comparison
| Readable Approach | Performant Approach | |
|---|---|---|
| Style | Named variables, step-by-step | Vectorized, compact one-liners |
| Speed | Slower on large data | Fast at scale |
| Learning Curve | Easy for beginners | Requires R expertise |
| When to Use | Teaching, exploration, small data | Production, large datasets |
| Documentation | Note performance ceiling | Note readability cost |
Question 1 of 5
What is the primary purpose of documenting a limitation in your R code?
Question 2 of 5
A classmate writes a for-loop that works correctly on 500 rows. They want to optimize it immediately with Rcpp. What should they do first?
Question 3 of 5
Which of the following is the best limitation comment?
Question 4 of 5
Code A:
\(\text{result <- sapply(1:n, function(i) sum(data[1:i]))}\)
Code B:
\(\text{result <- cumsum(data)}\)
Both produce the cumulative sum of a numeric vector \(\text{data}\).
Compared to Code A, Code B is:
Question 5 of 5
Where is the best place to document a major limitation that affects an entire R project?