Description Usage Arguments Details Examples

A very common problem with severe performance consequences is the ‘copy-and-append’ pattern. Save me from this craziness, and document that even the simple example below scales terribly. Do this in three steps. (1) Write a for-loop but pre-allocate the result vector and fill it in. (2) Use an sapply() to avoid thinking about pre-allocation. (3) implement the obvious vectorization.

1 | ```
loopy(n)
``` |

`n` |
a scalar (length 1) numeric non-negative vector indicating the number of a number will be |

Verify using `identical()`

that each solution returns the same
result for each implementation.

Verify the inefficiency of copy-and-append using microbenchmark to
evaluate the original function with different values of `n`

and plotting the result.

Verify the performance gain for a single value of `n`

across
the three implementations.

Find one StackOverflow question where the solution to a significant performance bottleneck is to avoid copy-and-append.

1 | ```
loopy(5)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.