The traditional way to compute the cumulative sum of a vector is with a
for loop. This is demonstrated with the function cumsum1().

The C++ standard template library (STL) has the partial_sum() function
that computes the cumulative sum of a vector. This is demonstrated with
the function cumsum2().

With Rcpp sugar, there is a cumsum() function which makes writing
this function in C++ very similar to using the cumsum function in R.

And we can of course compare the versions discussed here with the base R variant.