Learn R Programming

⚠️There's a newer version (0.1.2) of this package.Take me there.

papaja: Create APA manuscripts with R Markdown

papaja is a R-package in the making including a R Markdown template that can be used with (or without) RStudio to produce documents, which conform to the American Psychological Association (APA) manuscript guidelines (6th Edition). The package uses the LaTeX document class apa6 and a .docx-reference file, so you can create PDF documents, or Word documents if you have to. Moreover, papaja supplies R-functions that facilitate reporting results of your analyses in accordance with APA guidelines.

Note, at this point papaja is in active development and should be considered alpha. If you experience any problems, please open an issue on Github.

Examples

Take a look at the .Rmd of the example manuscript in the folder example and the resulting .pdf. The example document also contains some basic instructions.

Installation

Requirements

To use papaja you need to make sure the following software is installed on your computer:

  • R (2.11.1 or later)
  • RStudio (0.98.932 or later) is optional; if you don't use RStudio, you need to install pandoc using the instructions for your operating system
  • A TeX distribution (2013 or later; e.g., MikTeX for Windows, MacTeX for Mac, obviously, or TeX Live for Linux).
    • Windows users should use MikTex if possible. Currently, pandoc and the Windows version of Tex Live don't seem to like each other. Make sure you install the complete---not the basic---version.
    • Ubuntu 14.04 users need a few additional TeX packages for the document class apa6 to work:
sudo apt-get install texlive texlive-publishers texlive-fonts-extra texlive-latex-extra texlive-humanities lmodern

Install papaja

Once all that is taken care of, install papaja from GitHub:

devtools::install_github("crsh/papaja")

How to use papaja

Once papaja is installed, you can select the APA template when creating a new Markdown file through the RStudio menus.

If you want to add citations specify your BibTeX-file in the YAML front matter of the document (bibliography: my.bib) and you can start citing. If necessary, have a look at R Markdown's overview of the citation syntax. You may also be interested in citr, an R Studio addin to swiftly insert Markdown citations.

Helper functions to report analyses

The functions apa_print() and apa_table() facilitate reporting results of your analyses. Take a look at the .Rmd of the example manuscript in the folder example and the resulting .pdf.

Drop a supported analysis result, such as an htest- or lm-object, into apa_print() and receive a list of possible character strings that you can use to report the results of your analysis.

my_lm <- lm(Sepal.Width ~ Sepal.Length + Petal.Width + Petal.Length, data = iris)
apa_lm <- apa_print(my_lm)

One element of this list is apa_lm$table that, in the case of an lm-object, will contain a complete regression table. Pass apa_lm$table to apa_table() to turn it into a proper table in your PDF or Word document (remember to set the chunk option results = "asis").

apa_table(apa_lm$table, caption = "Iris regression table.")

Table. Iris regression table.

Predictorb95% CIt(146)p
Intercept1.04[0.51, 1.58]3.85< .001
Sepal Length0.61[0.48, 0.73]9.77< .001
Petal Width0.56[0.32, 0.80]4.55< .001
Petal Length-0.59[-0.71, -0.46]-9.43< .001

papaja currently provides methods for the following object classes:

AA-LL-SS
afex_aovaovlistlmsummary.aovlist
anovaglhtlsmobjsummary.glht
Anova.mlmhtestsummary.Anova.mlmsummary.lm
aovlistsummary.aovsummary.ref.grid

Be sure to also check out apa_barplot() and apa_beeplot() if you work with factorial designs. If you prefer creating your plots with ggplot2 try theme_apa().

Using papaja without RStudio

Don't use RStudio? No problem. Use the rmarkdown::render function to create articles:

# Create new R Markdown file
rmarkdown::draft(
  "mymanuscript.Rmd"
  , "apa6"
  , package = "papaja"
  , create_dir = FALSE
  , edit = FALSE
)

# Render manuscript
rmarkdown::render("mymanuscript.Rmd")

Known issues

  • The references in Word violate the APA guidelines in that there is no hanging indentation (i.e. indentation of all lines but the first one). As of now there is no fix for this problem.
  • Citations may mess with RStudios syntax highlighting in the current line. Incorrect highlighting following a citation does not necessarily indicate incorrect syntax.
  • Printing PDF from RStudio's PDF viewer can produce weird results. If you want to print your manuscript I suggest you use any other PDF viewer of your choice.

Contribute

Like papaja and want to contribute? Take a look at the open issues if you need inspiration. Other than that, there are many output objects from analysis methods that we would like apa_print() to support. Any new S3-methods for this function are always appreciated (e.g., glm, factanal, fa, lavaan, BFBayesFactor).

Papers that use papaja

Although papaja is not yet on CRAN and is still undergoing a lot of changes, there are peer-reviewed publications that use it. If you have published a paper that was written with papaja, let me know and I will add it to this list.

Stahl, C., Barth, M., & Haider, H. (2015). Distorted estimates of implicit and explicit learning in applications of the process-dissociation procedure to the SRT task. Consciousness & Cognition, 37, 27–43. doi: 10.1016/j.concog.2015.08.003

Aust, F., & Edwards, J. D. (2016). Incremental validity of Useful Field of View subtests for the prediction of Instrumental Activities of Daily Living. Journal of Clinical and Experimental Neuropsychology, 38, 497-515. doi: 10.1080/13803395.2015.1125453

Stahl, C., Haaf, J., & Corneille, O. (2016). Subliminal Evaluative Conditioning? Above-Chance CS Identification May Be Necessary and Insufficient for Attitude Learning. Journal of Experimental Psychology: General, 145 (9), 1107-1131. doi: 10.1037/xge0000191

Stahl, C. & Heycke, T. (2016). Evaluative Conditioning with Simultaneous and Sequential Pairings Under Incidental and Intentional Learning Conditions. Social Cognition, 34, 382-412. doi: 10.1521/soco.2016.34.5.382

Stahl, C., Henze, L., & Aust, F. (submitted). False memory for perceptually similar but conceptually distinct line drawings. Preprint retrieved from https://osf.io/preprints/psyarxiv/zr7m8/ (Data & R Markdown files)

Haaf, J. & Rouder, J. N. (submitted). Developing Constraint in Bayesian Mixed Models. Preprint retrieved from https://osf.io/preprints/psyarxiv/ktjnq/ (R Markdown files)

Heycke, T., Aust, F., & Stahl, C. (submitted). Crossmodal evaluative conditioning with briefly presented visual conditioned stimuli. Preprint retrieved from https://osf.io/preprints/psyarxiv/wntf5/ (Data & R Markdown files)

Rouder, J. N., Haaf, J., & Aust, F. (submitted). From theories to models to predictions: A Bayesian model comparison approach for communications research. Preprint retrieved from https://osf.io/preprints/psyarxiv/jt4th/

Other related R packages

By now, there are a couple of R packages that provide convenience functions to facilitate the reporting of statistics in accordance with APA guidelines.

  • apa: Format output of statistical tests in R according to APA guidelines
  • APAstats: R functions for formatting results in APA style and other stuff
  • apaTables: Create American Psychological Association (APA) Style Tables
  • pubprint: This package takes the output of several statistical tests, collects the characteristic values and transforms it in a publish-friendly pattern
  • schoRsch: Tools for Analyzing Factorial Experiments
  • sigr: Concise formatting of significances in R

Obviously, not all journals require manuscripts and articles to be prepared according to APA guidelines. If you are looking for other journal article templates, the following list of rmarkdown/pandoc packages and templates may be helpful.

If you know of other packages and templates, drop us a note, so we can add them here.

Copy Link

Version

Install

install.packages('papaja')

Monthly Downloads

1,919

Version

0.1.0.9492

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Frederik Aust

Last Published

September 29th, 2023

Functions in papaja (0.1.0.9492)

add_col_spanners

Add table headings to group columns
add_row_names

Add row names as first column
apa6_pdf

APA article (6th edition)
apa_barplot

Barplot for factorial designs that conform to APA guidelines
cite_r

Cite R and R-packages
conf_int

Between-subjects confidence intervals
apa_print.aov

Format statistics from ANOVA (APA 6th edition)
apa_print.glht

Format statistics (APA 6th edition)
apa_table

Prepare table for printing
arrange_anova

Create variance table from various ANOVA objects
fetch_web_refs

Fetch a .bib-reference file from the web (defunct)
fetch_zotero_refs

Save a collection from a Zotero-Account to a BibTeX-file
sanitize_terms

Sanitize term names
se

Standard errors
apa_beeplot

Beeswarm plots for factorial designs that conform to APA guidelines
apa_lineplot

Lineplot for factorial designs that conform to APA guidelines
apa_print.lm

Format statistics (APA 6th edition)
apa_print_container

Create empty container for results
merge_tables

Merge tables in list
papaja

APA manuscripts from RMarkdown
render_appendix

Render appendix
round_cells

Round table cells
word_title_page

Create title page
wsci

Within-subjects confidence intervals
apa_print.htest

Format statistics (APA 6th edition)
apa_print.list

Format statistics from ANOVA (APA 6th edition)
prettify_terms

Prettify term names
print_anova

Format statistics from ANOVA (APA 6th edition)
apa_prepare_doc

Prepare APA document (deprecated)
apa_print

Format statistics (APA 6th edition)
convert_stat_name

Convert name of statistic
defaults

Set defaults
in_paren

Replace parentheses with brackets
indent_stubs

Add stub indentation
print_confint

Create confidence interval string
print_model_comp

Format statistics model comparisons (APA 6th edition)
printnum

Prepare numeric values for printing
r_refs

Create a reference file for R and its packages
theme_apa

APA compatible ggplot2 theme
validate

Validate function input
escape_latex

Escape symbols for LaTex output
fast_aggregate

Aggregate data much faster using dplyr
sel

Select parameters
sort_effects

Sort ANOVA table by effects