Documenting workflows through a R script

Since I started using R my scripts have been getting really complicated.
I have recently thought that it is important to document the steps in the dataflow process, from extracting data from various sources, the transformation process, and the production of R Markdown reports.
Has anyone had a similar problem and implemented a solution that can advise on the best way of documenting this?

Hi @basile.

Too be honest, my scripts are tend to be messy, hence I'm not a best adviser on that topic.
My suggestion would be to check as a guide to writing a clear readable code.