I mostly code in R, and have been using knitr Rnw for a while, mostly following the best practices outline in 14mech14's YouTube videos, with a parent rnw document, child rnw document, and a document for my R code and all the tables / figures.
I recently started experimenting with Rmd for my journal articles using the rticles package, but just ran into the issue of having to load new packages into the Rmd document. I have seen Yihui's document, but it doesn't seem to work if I have
output: rticles::aea_article
extra_dependencies: ["rotating"]
How do I solve this issue? (Moreover, if I have colleagues that work in STATA, how do I enable them to work on the paper as well? Should I just write everything in Latex itself and export?)
Here is my .Rmd file:
---
title: "BLAH"
month: "`r format(Sys.Date(), '%m')`"
year: "`r format(Sys.Date(), '%Y')`"
author:
- name: Myself
firstname: Nobody
surname: Owens
email: nobody.owens@blob.edu
affiliation: some institute of technology
acknowledgements: |
Thank you to my humble research assistant for his research assistance.
abstract: |
This is the abstract.
output: rticles::aea_article
---
```{r setup, include=FALSE}
# this R code imports my data from the .R file: (of course for this online example I don't have a file to show)
knitr::opts_chunk$set(echo = FALSE, warning = FALSE)
# IMPORT PACKAGES-------------
list.of.packages <- c("dplyr", "data.table","ggplot2", "kableExtra", "tinytex", "stargazer")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[, "Package"])]
if (length(new.packages)) install.packages(new.packages)
for (package in list.of.packages) {library(eval((package)), character.only = TRUE)}
# LOAD THE DATA FROM THE .R FILE---------
# load(".RData")
```
Blah blah blah...
This works, because it's a small table.
```{r, echo = FALSE, warning = FALSE}
# some table with kableExtra package:
# just an example...
a <- data.frame(a = c("orcs","orcs","elves", "elves", "elves"), b = c(1,2,3,4,5), c = c(1,2,3,4,5))
a %>% kbl(
.,
booktabs = TRUE,
linesep = "",
caption = "Model Summary Statistics",
label = "meansd"
) %>%
kableExtra::column_spec(column = 2:3, width = "0.5in") %>%
kableExtra::collapse_rows(columns = 1,
valign = "middle",
longtable_clean_cut = FALSE) %>%
kable_styling(
font_size = 4,
latex_options =
c("hold_position",
"condensed")
)
```
But what if I have a big one...?
\begin{table}[!htbp]\centering
\caption{My Regressions}
\label{tab:nobodyowensregressions}
```{r, results = "asis"}
# this is some code from my original .R file that gets saved into the .RData file:
panelfit <- list()
for (i_ in c(1:10)){
panelfit[[i_]] <- lm(b~c, data = a)
}
model.smmrys.tex <-
R.utils::captureOutput(
stargazer(
panelfit,
type="latex",
font.size = "footnotesize",
style = "aer",
float = FALSE,
column.sep.width = "-12pt",
df = FALSE,
dep.var.labels = "",
dep.var.caption = ""
)
)
cat(model.smmrys.tex, sep = "\n")
```
\end{table}
Ideally, I'd like to be able to do something like \begin{sidewaysfigure}, \end{sidewaysfigure} before and after the table. Landscape doesn't work here because AEA is twosided. Do I just have to edit the base .Tex file? (I'm fine with that, but was hoping for an Rmd solution).
Note: You have to have the AEA cls file from the rticles package in the same directory as this Rmd document in order for this to run.
Note2: I have posted on the rticles Github page
I just found out this question has already been asked here
xtable
orggplot2
, and write the paper itself fully in LaTeX. But I guess this is opinion based, so I'll vote to close.rticles
.