A simple and lighter way to use R-markdown without needing to download Rstudio.
Depending on your OS the installation process can be different, but it won't be hard, for linux on ubuntu distros, we use:
sudo apt update
sudo apt install r-base
sudo apt install pandoc
If you want a smaller R version, install r-base-core
and also run sudo apt-get autoremove
to uninstall unnecessary packages.
With your R installed, we can run it and install some packages (rmarkdown and reticulate), rmarkdown installation can take a while:
R
> install.packages("rmarkdown")
> install.packages("tinytex")
> tinytex::install_tinytex()
> install.packages("reticulate") # optional: to run any programming language inside your documentation
To update your document while you're editting it, we're going to use nodemon, but you can configure whatever you prefer.
Again I'm going to use linux ubuntu distros download method.
sudo apt install npm
sudo npm i -g nodemon
Create a Makefile to automate the running process:
filename ?= test.Rmd
render:
Rscript -e "rmarkdown::render('$(filename)')"
dev:
nodemon -w "$(filename)" --exec "make render"
Then, just run make dev, and 'voilà' it's working, just open the pdf file and see what you've made. If you want to see what's changing in real time, some apps have this syncronization, including the default PDF reader of ubuntu and vscode-pdf extension.
Just rename the filename in the Makefile, and run make dev
on your project folder. Or run make dev filename=myfile.Rmd
.
I added a templateScript.sh file, to setup a terminal command to create new .Rmd documents from the template (also with the Makefile). Just run:
chmod +x "./templateScript.sh"
./templateScript.sh
And the you can run Rmakeless
to create a new document based on the template file.