ggplot2::geom_path() in a loop

This happens in R to the dismay of visitors from procedural imperative languages.

This issue is that nothing to be output is called for until the loop ends, and that only returns the last iteration.

The fix is to initialize a vector or list in the global environment and increment it within the loop.

holder = rep(NA,10)
for (i in 1:10) holder[i] = i^2
holder
#>  [1]   1   4   9  16  25  36  49  64  81 100

Created on 2021-04-23 by the reprex package (v2.0.0)