r对象未在文本中打印

时间:2018-12-26 21:39:11

标签: r papaja

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

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

1 个答案:

答案 0 :(得分:1)

好问题。在papaja中,这不是预期的行为,很快将在开发版本中修复。问题是内联挂钩无法正确处理列表。如果选择列表元素以使输出对象是矢量,则它也应在当前版本中工作。

您可以使用s1$estimate[2][1],也可以使用s1$estimate[[2]],但就我个人而言,我更喜欢通过s1$estimate[["xtreat"]]s1$estimate$xtreat按名称建立索引。

顺便说一句,如果您想报告估计值和检验统计数据,则可以使用full_result元素。

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

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