{"id":13707784,"url":"https://github.com/crsh/papaja","last_synced_at":"2025-05-15T17:09:00.589Z","repository":{"id":18817269,"uuid":"22032048","full_name":"crsh/papaja","owner":"crsh","description":"papaja (Preparing APA Journal Articles) is an R package that provides document formats to produce complete APA manuscripts from RMarkdown-files (PDF and Word documents) and helper functions that facilitate reporting statistics, tables, and plots.","archived":false,"fork":false,"pushed_at":"2025-05-07T15:41:26.000Z","size":16766,"stargazers_count":669,"open_issues_count":82,"forks_count":136,"subscribers_count":24,"default_branch":"main","last_synced_at":"2025-05-12T19:09:07.525Z","etag":null,"topics":["apa","apa-guidelines","journal","manuscript","psychology","r","r-package","reproducible-paper","reproducible-research","rmarkdown"],"latest_commit_sha":null,"homepage":"https://frederikaust.com/papaja_man/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crsh.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-07-20T11:43:41.000Z","updated_at":"2025-05-08T02:50:42.000Z","dependencies_parsed_at":"2023-02-14T07:46:12.847Z","dependency_job_id":"68682799-d35d-4b8a-8e1a-948822b63aea","html_url":"https://github.com/crsh/papaja","commit_stats":{"total_commits":1375,"total_committers":19,"mean_commits":72.36842105263158,"dds":0.5578181818181818,"last_synced_commit":"9c569a3366068dd5408171d14993c651f1b39c73"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crsh%2Fpapaja","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crsh%2Fpapaja/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crsh%2Fpapaja/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crsh%2Fpapaja/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crsh","download_url":"https://codeload.github.com/crsh/papaja/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254384989,"owners_count":22062422,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apa","apa-guidelines","journal","manuscript","psychology","r","r-package","reproducible-paper","reproducible-research","rmarkdown"],"created_at":"2024-08-02T22:01:43.390Z","updated_at":"2025-05-15T17:08:55.581Z","avatar_url":"https://github.com/crsh.png","language":"HTML","funding_links":[],"categories":["R","HTML"],"sub_categories":[],"readme":"---\ntitle : \"\u003cimg src='tools/images/papaja_hex.png' align='right' height='150' /\u003epapaja: Prepare APA Journal Articles\u003cbr /\u003ewith R Markdown\"\noutput: github_document\n  # github_document:\n  #   toc: true\n  #   toc_depth: 2\n---\n\n```{r include = FALSE}\nif(!requireNamespace(\"depgraph\", quietly = TRUE)) remotes::install_github(\"crsh/depgraph\")\n```\n\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n[![CRAN/METACRAN](https://img.shields.io/cran/v/papaja?label=CRAN\u0026logo=r)]( https://cran.r-project.org/package=papaja) [![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) ![GitHub last commit (main)](https://img.shields.io/github/last-commit/crsh/papaja/main?label=Last%20commit\u0026logo=github) [![R-CMD-check](https://github.com/crsh/papaja/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/crsh/papaja/actions/workflows/R-CMD-check.yaml) [![codecov](https://codecov.io/gh/crsh/papaja/branch/master/graph/badge.svg)](https://app.codecov.io/gh/crsh/papaja) [![GitHub bug issues](https://img.shields.io/github/issues/crsh/papaja/bug?label=Bugs\u0026logo=github)](https://github.com/crsh/papaja/issues?q=is%3Aopen+is%3Aissue+label%3Abug) [![StackOverflow questions](https://img.shields.io/stackexchange/stackoverflow/t/papaja?label=Questions\u0026logo=stackoverflow)](https://stackoverflow.com/questions/tagged/papaja)\n\n**Sections** [Example](#example) | [Installation](#installation) | [Usage](#usage) | [Getting help](#getting-help) | [Citation](#citation) | [papaja in the wild](#papaja-in-the-wild) | [Computational reproducibility](#computational-reproducibility) | [Contribute](#contribute) | [Related R packages](#related-r-packages) | [Package dependencies](#package-dependencies)\n\n**papaja** is an [award-winning](https://improvingpsych.org/mission/awards/) R package that facilitates creating computationally reproducible, submission-ready manuscripts which conform to the American Psychological Association (APA) manuscript guidelines (6th Edition).\n**papaja** provides\n\n-   an [R Markdown](https://rmarkdown.rstudio.com/) template that can be used with (or without) [RStudio](https://posit.co/) to create PDF documents (using the [apa6](http://www.ctan.org/pkg/apa6) LaTeX class) or Word documents (using a .docx-reference file).\n-   Functions to **typeset** the results from **statistical analyses**,\n-   functions to create **tables**, and\n-   functions to create **figures** in accordance with APA guidelines.\n\nFor a comprehensive introduction to **papaja**, see the current draft of the [manual](https://frederikaust.com/papaja_man/).\nIf you have a specific question that is not answered in the manual, feel free to ask a question on Stack Overflow [using the **papaja** tag](https://stackoverflow.com/questions/tagged/papaja).\nIf you believe you have found a bug or would like to request a new feature, [open an issue](https://github.com/crsh/papaja/issues) on Github and provide a [minimal complete verifiable example](https://stackoverflow.com/help/minimal-reproducible-example).\n\n## Example\n\nTake a look at the [source file](https://github.com/crsh/papaja/blob/master/vignettes/papaja.Rmd) of the package vignette and the resulting [PDF](https://raw.githubusercontent.com/crsh/papaja/master/vignettes/papaja.pdf).\nThe vignette also contains some basic instructions.\n\n## Installation\n\nTo use **papaja** you need either a recent version of [RStudio](https://posit.co/) or [pandoc](https://pandoc.org/).\nIf you want to create PDF- in addition to DOCX-documents you additionally need a [TeX](https://en.wikipedia.org/wiki/TeX) distribution.\nWe recommend you use [TinyTex](https://yihui.org/tinytex/), which can be installed from within R:\n\n```{r eval = FALSE}\nif(!requireNamespace(\"tinytex\", quietly = TRUE)) install.packages(\"tinytex\")\n\ntinytex::install_tinytex()\n```\n\nYou may also consider [MikTeX](https://miktex.org/) for Windows, [MacTeX](https://tug.org/mactex/) for Mac, or [TeX Live](https://tug.org/texlive/) for Linux.\nPlease refer to the [**papaja** manual](https://frederikaust.com/papaja_man/introduction.html#getting-started) for detailed installation instructions.\n\n**papaja** is available on CRAN but you can also install it from the GitHub repository:\n\n```{r install_papapja, eval = FALSE}\n# Install latest CRAN release\ninstall.packages(\"papaja\")\n\n# Install remotes package if necessary\nif(!requireNamespace(\"remotes\", quietly = TRUE)) install.packages(\"remotes\")\n\n# Install the stable development version from GitHub\nremotes::install_github(\"crsh/papaja\")\n```\n\n## Usage\n\nOnce **papaja** is installed, you can select the APA template when creating a new R Markdown file through the RStudio menus.\n\n![APA template selection dialog](inst/images/template_selection.png)\n\nTo add citations, specify your bibliography-file in the YAML front matter of the document (`bibliography: my.bib`) and start citing (for details, see pandoc manual on the [citeproc extension](https://pandoc.org/MANUAL.html#extension-citations). You may also be interested in [**citr**](https://github.com/crsh/citr), an R Studio addin to swiftly insert Markdown citations and [R Studio's visual editor](https://rstudio.github.io/visual-markdown-editing/), which also enables swiftly [inserting citations](https://rstudio.github.io/visual-markdown-editing/citations.html).\n\n### Typeset analysis results\n\nThe functions `apa_print()` and `apa_table()` facilitate reporting results of your analyses.\nWhen you pass the an output object of a supported class, such as an `htest`- or `lm`-object, to `apa_print()`, it will return a list of character strings that you can use to report the results of your analysis.\n\n```{r echo = FALSE, message = FALSE, warning = FALSE, results = 'hide'}\nlibrary(\"papaja\")\n```\n\n```{r}\nmy_lm \u003c- lm(\n  Sepal.Width ~ Sepal.Length + Petal.Width + Petal.Length\n  , data = iris\n)\napa_lm \u003c- apa_print(my_lm)\n\napa_lm$full_result$Sepal_Length\n```\n\n**papaja** currently provides methods for the following object classes:\n\n```{r echo = FALSE, results = \"asis\"}\nprint_classes \u003c- gsub(\"apa_print\\\\.\", \"\", as.character(utils::methods(\"apa_print\")))\nprint_classes \u003c- print_classes[!grepl(\",\", print_classes)]\nprint_classes \u003c- c(print_classes, rep(NA,  (4 - length(print_classes) %% 4) * (length(print_classes) %% 4 \u003e 0)))\nprint_classes \u003c- matrix(print_classes, ncol = 4)\ncolnames(print_classes) \u003c- apply(print_classes, 2, function(x) {\n  first_letters \u003c- tolower(substr(x, 1, 1))\n  first_letters \u003c- c(first_letters[1], tail(first_letters, 1))\n  first_letters[is.na(first_letters)] \u003c- \"z\"\n  col_names \u003c- if(first_letters[1] == first_letters[2]) first_letters[1] else paste(first_letters, collapse = \"-\")\n  toupper(col_names)\n})\nprint_classes[is.na(print_classes)] \u003c- \"\"\n\nknitr::kable(print_classes)\n```\n\n\n### Create tables\n\n`apa_table()` may be used to produce publication-ready tables in an R Markdown document.\nFor instance, you might want to report some condition means (with standard errors).\n\n```{r message = FALSE, eval = FALSE}\nnpk |\u003e\n  # Summarize data\n  dplyr::group_by(N, P) |\u003e\n  dplyr::summarise(\n    mean = mean(yield)\n    , se = sd(yield) / sqrt(length(yield))\n    , .groups = \"drop\"\n  ) |\u003e\n  # Label columns \n  label_variables(\n    N = \"Nitrogen\"\n    , P = \"Phosphate\"\n    , mean = \"*M*\"\n    , se = \"*SE*\"\n  ) |\u003e\n  # Print table\n  apa_table(caption = \"Mean pea yield (with standard errors)\")\n```\n\nTable 1.\n*Mean pea yield (with standard errors)*\n\n```{r echo = FALSE, message = FALSE}\nlibrary(\"dplyr\")\nout \u003c- npk %\u003e%\n  group_by(N, P) %\u003e%\n  summarise(mean = mean(yield), se = sd(yield) / sqrt(length(yield)), .groups = \"drop\")\ncolnames(out) \u003c- c(\"Nitrogen\", \"Phosphate\", \"*M*\", \"*SE*\")\nknitr::kable(out, align = \"c\", digits = 2)\n```\n\nThis is a fairly simple example, but `apa_table()` may be used to generate [more complex tables](https://osf.io/s4968/).\n\n`apa_table()`, of course, plays nicely with the output from `apa_print()`.\nThus, it is possible to conveniently report complete regression tables, ANOVA tables, or the output from mixed-effects models.\n\n```{r eval = FALSE}\nlm(Sepal.Width ~ Sepal.Length + Petal.Width + Petal.Length, data = iris) |\u003e\n  apa_print() |\u003e\n  apa_table(caption = \"Iris regression table.\")\n```\n\nTable 2.\n*Iris regression table.*\n\n```{r echo = FALSE}\nout \u003c- lm(Sepal.Width ~ Sepal.Length + Petal.Width + Petal.Length, data = iris) |\u003e\n  apa_print()\n\nout$table$p.value \u003c- gsub(\" \", \"\u0026nbsp;\", out$table$p.value)\n\ncol_labels \u003c- unlist(variable_labels(out$table))\ncol_labels[\"df\"] \u003c- \"$df$\"\ncolnames(out$table) \u003c- gsub(\"\\\\$\", \"*\", col_labels)\n\nknitr::kable(out$table, align = \"lrcrr\")\n```\n\n### Create figures\n\n**papaja** further provides functions to create publication-ready plots.\nFor example, you can use `apa_barplot()`, `apa_lineplot()`, and `apa_beeplot()` (or the general function `apa_factorial_plot()`) to visualize the results of factorial study designs:\n\n```{r include = FALSE}\nset.seed(42L)\nx \u003c- expand.grid(\n  id = seq_len(80L)\n  , congruency = c(\"Congruent\", \"Incongruent\")\n  , load       = c(\"High\", \"Low\")\n)\n\nx[[\"response_time\"]] \u003c- rt(nrow(x), df = 20) * 80 + \n  (x$congruency == \"Congruent\") * - 80 + \n  (x$load == \"High\") * 40 + \n  500\n\n\nvariable_labels(x) \u003c- list(\n  congruency = \"Congruency\"\n  , load = \"Cognitive load\"\n  , response_time = \"Response time\"\n)\nstroop_data \u003c- x\n```\n\n```{r stroop-plot, fig.cap = \"Response times from a simulated Stroop experiment. Large dots represent condition means, small dots represent individual participants' mean response time. Error bars represent 99% within-subjects confidence intervals.\"}\napa_beeplot(\n  data = stroop_data\n  , dv = \"response_time\"\n  , id = \"id\"\n  , factors = c(\"congruency\", \"load\")\n  , ylim = c(0, 800)\n  , dispersion = wsci # within-subjects confidence intervals\n  , conf.level = .99\n  , las = 1\n)\n```\n\nIf you prefer `ggplot2`, try `theme_apa()`.\n\n```{r stroop-ggplot}\nlibrary(\"ggplot2\")\nlibrary(\"ggforce\")\n\np \u003c- ggplot(\n  stroop_data\n  , aes(x = congruency, y = response_time, shape = load, fill = load)\n) +\n  geom_violin(alpha = 0.2, color = grey(0.6)) +\n  geom_sina(color = grey(0.6)) +\n  stat_summary(position = position_dodge2(0.95), fun.data = mean_cl_normal) +\n  lims(y = c(0, max(stroop_data$response_time))) +\n  scale_shape_manual(values = c(21, 22)) +\n  scale_fill_grey(start = 0.6, end = 1) +\n  labs(\n    x = \"Congruency\"\n    , y = \"Response time\"\n    , shape = \"Cognitive load\"\n    , fill = \"Cognitive load\"\n  )\n\np + theme_apa()\n```\n\n### Usage without RStudio\n\nDon't use RStudio?\nNo problem.\nUse the `rmarkdown::render` function to create articles:\n\n``` r\n# Create new R Markdown file\nrmarkdown::draft(\n  \"mymanuscript.Rmd\"\n  , \"apa6\"\n  , package = \"papaja\"\n  , create_dir = FALSE\n  , edit = FALSE\n)\n\n# Render manuscript\nrmarkdown::render(\"mymanuscript.Rmd\")\n```\n\n## Getting help\n\n[![StackOverflow questions](https://img.shields.io/stackexchange/stackoverflow/t/papaja?label=Questions\u0026logo=stackoverflow)](https://stackoverflow.com/questions/tagged/papaja)\n\nFor a comprehensive introduction to **papaja**, check out the current draft of the [**papaja** manual](https://frederikaust.com/papaja_man/).\nIf you have a specific question that is not answered in the manual, feel free to ask a question on Stack Overflow [using the **papaja** tag](https://stackoverflow.com/questions/tagged/papaja).\nIf you believe you have found a bug or you want to request a new feature, [open an issue](https://github.com/crsh/papaja/issues) on Github and provide a [minimal complete verifiable example](https://stackoverflow.com/help/minimal-reproducible-example).\n\n## Citation\n\nPlease cite **papaja** if you use it.\n\n    `r attr(unclass(citation(\"papaja\"))[[1]], \"textVersion\")`\n\nFor convenience, you can [use `cite_r()`](https://frederikaust.com/papaja_man/writing.html#citing-r-and-its-packages) or copy the reference information returned by `citation('papaja')` to your BibTeX file:\n\n~~~bibtex\n\n```{r echo = FALSE, results = \"asis\"}\nprint(citation(\"papaja\"), style = \"Bibtex\")\n```\n\n~~~\n\n## papaja in the wild\n\nIf you are interested in seeing how others are using **papaja**, you can find a [collection of papers](https://frederikaust.com/papaja_man/published-manuscripts.html) and the corresponding R Markdown files in the manual.\n\nIf you have published a paper that was written with **papaja**, please add the reference to the [public Zotero group](https://www.zotero.org/groups/2202906/papaja) yourself or send us to me.\n\n## Computational reproducibility\n\nTo ensure mid- to long-term computational reproducibility we highly recommend conserving the software environment used to write a manuscript (e.g. R and all R packages) either in a software container or a virtual machine.\nThis way you can be sure that your R code does not break because of updates to R or any R package.\nFor a brief primer on containers and virtual machines see [the supplementary material](https://psych-transparency-guide.uni-koeln.de/analytic-reproducibility.html#document-hardware-and-software-used-for-analyses) by Klein et al. (2018).\n\n[Docker](https://www.docker.com/) is the most widely used containerization approach.\nIt is open source and free to use but requires some disk space.\n[CodeOcean](https://codeocean.com/) is a commercial service that builds on Docker, facilitates setting up and sharing containers and lets you run computations in the cloud.\nSee the **papaja** manual on [how to get started using **papaja** with Docker or CodeOcean](https://frederikaust.com/papaja_man/tips-and-tricks.html#reproducible-software-environments) and [our Docker workflow](https://github.com/crsh/papaja_docker) tailored for easy use with **papaja**.\n\n## Contribute\n\n[![GitHub help wanted issues](https://img.shields.io/github/issues/crsh/papaja/help%20wanted?logo=github\u0026logoColor=%2523FFF)](https://github.com/crsh/papaja/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) [![GitHub documentation issues](https://img.shields.io/github/issues/crsh/papaja/documentation?logo=github\u0026logoColor=%2523FFF)](https://github.com/crsh/papaja/issues?q=is%3Aopen+is%3Aissue+label%3Adocumentation)\n\nLike **papaja** and want to contribute?\nWe highly appreciate any contributions to the R package or its documentation.\nTake a look at the [open issues](https://github.com/crsh/papaja/issues) if you need inspiration.\nThere are many additional analyses that we would like `apa_print()` to support.\nAny new S3/S4-methods for this function are always appreciated (e.g., `factanal`, `fa`, `lavaan`).\nFor a primer on adding new `apa_print()`-methods, see the getting-started-vignette:\n\n```r\nvignette(\"extending_apa_print\", package = \"papaja\")\n```\n\nBefore working on a contribution, please review our brief [contributing guidelines](https://github.com/crsh/papaja/blob/main/.github/CONTRIBUTING.md) and [code of conduct](https://github.com/crsh/papaja/blob/main/CODE_OF_CONDUCT.md).\n\n## Related R packages\n\nBy now, there are a couple of R packages that provide convenience functions to facilitate the reporting of statistics in accordance with APA guidelines.\n\n-   [**apa**](https://github.com/dgromer/apa): Format output of statistical tests in R according to APA guidelines\n-   [**APAstats**](https://github.com/achetverikov/APAstats): R functions for formatting results in APA style and other stuff\n-   [**apaTables**](https://github.com/dstanley4/apaTables): Create American Psychological Association (APA) Style Tables\n-   [**rempsyc**](https://github.com/RemPsyc/rempsyc): Convenience functions for psychology\n-   [**sigr**](https://github.com/WinVector/sigr): Concise formatting of significances in R\n-   [**apaquarto**](https://github.com/wjschne/apaquarto): A quarto extension for creating APA7 documents in .docx, .html, and .pdf formats\n\nIf you are looking for other journal article templates, you may be interested in the [**rticles**](https://github.com/rstudio/rticles) package.\n\n## Package dependencies\n\n```{r dep-plot, echo = FALSE, fig.width = 10, fig.height = 9, message = FALSE, warning = FALSE}\ndepgraph::plot_dependency_graph(\n  pkg = \".\"\n  , repos = \"https://cran.rstudio.com/\"\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrsh%2Fpapaja","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrsh%2Fpapaja","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrsh%2Fpapaja/lists"}