1

Some R objects that are printed in Rmarkdown without a problem but is not printed using papaja template. It does not generate any any error message. For example, let's say I wrote a markdown file as below:

```{r setup, include = FALSE}
knitr::opts_chunk$set(include = FALSE)
```


```{r}
library("pacman")
p_load(plyr, dplyr, ggplot2, lmSupport, lme4, psycho, psych, 
GPArotation, tidyverse, tinytex, afex, foreign,purrr, lavaan, citr, 
papaja)
options(scipen = 0, digits = 3) 
DF <- data.frame(id = paste0("ID.", 1:200), 
    x = sample(c("control", "treat"), 200, replace = TRUE),
    y = rnorm(200))
m <- lm(y ~x, data= DF)
summary(m)
s1<-apa_print.lm(m)
s1$statistic[2]
```

# Result

I fitted a  linear regression model in which condition (control vs. 
treat) predicts scores. Treat group showed significantly higher scores 
compared to control group, `r s1$estimate[2]`, `r s1$statistic[2]`. 
ffew
  • 15
  • 4
  • I added the triple-backticks to the two code blocks. I thought about fixing the inline code (making them `\`r s1$estimate[1]\``, etc), but I wasn't certain how exactly you put them into your document. It would be helpful to see your raw Rmd text that includes this *as code*, that is copy a portion of the paragraph with the inline code and indent as a code block (four leading spaces). – r2evans Dec 26 '18 at 23:10
  • Ok, now I see that changing the last part to `r s1$estimate[2][1]`,`r s1$statistic[2][1]` solves the problem. I'm just curious why my initial code worked in a default template...., which made me think it should be an issue with papaja. Would you have any clue? @r2evans ? – ffew Dec 27 '18 at 03:26
  • Sorry, I've never used `papaja`, and it's not clear to me why that would have made as big a difference. – r2evans Dec 27 '18 at 03:40

1 Answers1

1

Good question. This is not intended behavior in papaja and will be fixed shortly in the development version. The issue is that the inline hook doesn't properly handle lists. If you select the list element such that the output object is a vector it should also work in the current version.

You could either use, s1$estimate[2][1] as you have found, or s1$estimate[[2]], but personally, I'd prefer indexing by name via s1$estimate[["xtreat"]] or s1$estimate$xtreat.

As an aside, if you want to report estimates and test statistics, you can use the full_result-element.

So for your example, I'd suggest:

```{r setup, include = FALSE}
library("papaja")
```

```{r}
DF <- data.frame(id = paste0("ID.", 1:200), 
    x = sample(c("control", "treat"), 200, replace = TRUE),
    y = rnorm(200))
m <- lm(y ~ x, data = DF)
s1 <- apa_print.lm(m)
```

# Result

I fitted a  linear regression model in which condition (control vs. 
treat) predicts scores. Treat group showed significantly higher scores 
compared to control group, `r s1$full_result$xtreat`. 
crsh
  • 1,699
  • 16
  • 33