R code for SPRUCE