Is there a way to export all the code from RStudio and the output into a .txt file?
https://rmarkdown.rstudio.com/articles_report_from_r_script.html
This should do it. It's an RMarkdown feature that lets you automatically report your script. It includes the source code and the outputs. I believe there's a MSWord format and a PDF format.