1

一些在 Rmarkdown 中打印没有问题但没有使用 papaja 模板打印的 R 对象。它不会生成任何错误消息。例如,假设我写了一个降价文件,如下所示:

```{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]`. 
4

1 回答 1

1

好问题。这不是预期的行为,papaja将很快在开发版本中修复。问题是内联钩子不能正确处理列表。如果您选择列表元素使得输出对象是一个向量,它也应该在当前版本中工作。

如您所见,您可以使用s1$estimate[2][1]or s1$estimate[[2]],但就个人而言,我更喜欢通过名称索引s1$estimate[["xtreat"]]or s1$estimate$xtreat

顺便说一句,如果你想报告估计和测试统计,你可以使用full_result-element。

因此,对于您的示例,我建议:

```{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`. 
于 2019-01-21T15:33:57.213 回答