/knitr-template-apa

A template for APA-style articles written in knitr / LaTeX

Primary LanguageMakefile

rupavatara.jpg

A template for APA style articles written in knitr / LaTeX. The problem this template tries to solve is that there are many moving parts that one needs to pay attention to when starting a new document from scratch. This template aims to give authors a solid starting point that implements common best practices and that should work as a good starting point for most documents. The focus of this template is on use cases in (psycho)linguistics, but it’s not strictly limited to that area. Suggestions for improvements and pull requests are welcome.

How to use knitr in RStudio

RStudio extensive support for knitr documents. See the following documents for instructions:

How to compile the template to PDF on Linux and Mac Os X using a command shell

Open a command shell in the directory containing the .Rnw file and executed the following sequence of commands:

Rscript -e "library(knitr); knit('manuscript.Rnw')"
pdflatex manuscript
biber manuscript
pdflatex manuscript
pdflatex manuscript

Alternatively you can just use the Makefile to automatize this process. Just open a command shell in the directory containing the .Rnw file and enter make.

How to compile the template in Windows using a command shell

(Description contributed by @epankratz and slightly adapted.)

Run this sequence of commands in a command shell:

Rscript.exe -e "library(knitr); knit('manuscript.Rnw')"
pdflatex manuscript
biber manuscript
pdflatex manuscript
pdflatex manuscript

If the Rscript.exe command doesn’t work by default because it’s not a recognized command, you need to add the location of Rscript.exe to the system PATH variable, for instance C:/Program Files/R/R-3.6.1/bin. Find the equivalent on your system and follow the instructions here so that Windows knows where to find Rscript.exe.

If the Rscript command doesn’t work because the package knitr can’t be found, your packages might be installed in the wrong place. They have to be installed under the path that is printed when you enter:

Rscript -e ".libPaths()"

This path is probably your system library (e.g., C:/Program Files/R/R-3.6.1/library), not your user library.

To install packages into the system library, rather than your user library, run RStudio as an administrator to gain the necessary permissions. If you now open the package installer in RStudio (Tools > Install Packages), you should see the path to the system library under “Install to Library”. Install knitr and whatever other packages you need including all dependencies.

Now running the commands above should work.

Some helpful links: