How to use Rstudio, Overleaf v2, and Sphinx to write and publish data-driven documents

While this is very much a work in progress and I am building proofs-of-concept, combining Rstudio (you can use regular R and a text editor as well, it does not have to be Rstudio), using R, a text editor (I tried using geany on a linux laptop and in theory it should work well, but geany misbehaved), sphinx, and overleaf v2 (the latest version of Overleaf) can make for excellent combination of write once publish everywhere. I will write more in details, but here are the steps:

  1. Start a project in Overleaf version 2 (assume that you already have an account on Overleaf; if not, get a free account)
  2. Set up the link of the Overleaf project with github (assume that you already have a github account, if not, get a free account on github)
  3. Clone the github repo with git clone <github repo address>
  4. Change into this directory cd github_repo_folder
  5. Assuming you have installed sphinx, do sphinx-quickstart in this folder, and follow the instructions to set up your sphinx folders. Most instructions are intuitive, be sure to say yes to sphinx.autodoc
  6. Assuming you have R installed (if not, install R from the R website), install install.packages("knitr") from within the R app; or if you have Rstudio installed, I think it comes with knitr package
  7. Create a file touch foo.Rrst. I named it foo but you can give it any name.
  8. Write R codes and weave restructuredtext materials in this file. I recommend that for best results, continue to run your R codes in a separate file and use only relevant R code segments in the foo.Rrst file.
  9. When you are done, in R, do knit("foo.Rrst") and it will generate a foo.rst file. Add this foo.rst file to your index.rst file list.
  10. Then, do make latex.
  11. Then git add ., git commit -m "your message here" and git push to populate your repo.
  12. Pull in the files to your Overleaf and enjoy

You will have to do many of these steps only once. At the moment, you will see everything in the form of a documentation text. I do not like this, so my todo list will include altering the set up of the file in sphinx to make it look like a thesis or book, or report, or article for that matter.