I suggest you read Chapter 8 in Forecasting: Principles and Practice, which is online (and free) at https://otexts.com/fpp3/
The book includes R code using the tidyverts set of packages, which is the next generation of the widely used {forecast} package by Rob Hyndman. I highly recommend it!