I don't have bookdown
installed, and hence can't try myself, but I'll suggest you to use pull
once (in place of select
in inline codes) and see what happens.
And, I edited your thread. I added four backticks (````
) before and after the code to display the file content as it is. I hope you won't mind.
Edit
While I suggested, I thought pull
may work as it'd return a vector instead of a tibble. But unfortunately, now that doesn't seem to be enough explanation.
Here's what I tried:
---
title: "test"
output:
html_document: default
pdf_document: default
---
blah blah blah
```{r}
library(broom)
library(dplyr)
p <- t.test(formula = extra ~ group, data = sleep)
q <- tidy(x = p)
```
blah `r q %>% select(statistic)` blah `r q %>% select(p.value)` blah
blah `r q %>% pull(statistic)` blah `r q %>% pull(p.value)` blah
```{r}
str(object = q)
```
blah blah blah
As you have noticed, HTML output is fine.
But PDF is not. While using select
, it is showing c
for the statistic value, but not for p value.
I checked the types of statistic
and p.value
, and both are of same type. So, there is some other reason that I do not know. May be someone more familiar with these may help.
System Information
> xfun::session_info()
## R version 4.0.3 (2020-10-10)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Catalina 10.15.7
##
## Locale: en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8
##
## Package version:
## assertthat_0.2.1 backports_1.2.1 base64enc_0.1.3 broom_0.7.3
## cli_2.2.0 compiler_4.0.3 cpp11_0.2.4 crayon_1.3.4
## digest_0.6.27 dplyr_1.0.2 ellipsis_0.3.1 evaluate_0.14
## fansi_0.4.1 generics_0.1.0 glue_1.4.2 graphics_4.0.3
## grDevices_4.0.3 highr_0.8 htmltools_0.5.0 jsonlite_1.7.2
## knitr_1.30 lifecycle_0.2.0 magrittr_2.0.1 markdown_1.1
## methods_4.0.3 mime_0.9 pillar_1.4.7 pkgconfig_2.0.3
## purrr_0.3.4 R6_2.5.0 rlang_0.4.9 rmarkdown_2.6
## stats_4.0.3 stringi_1.5.3 stringr_1.4.0 tibble_3.0.4
## tidyr_1.1.2 tidyselect_1.1.0 tinytex_0.28 tools_4.0.3
## utf8_1.1.4 utils_4.0.3 vctrs_0.3.6 xfun_0.19
## yaml_2.2.1
Edit
I wanted an explanation why select
behaves differently for statistic
and p.value
.
See the pdf output for this line:
blah `r q %>% select(statistic)` blah `r q %>% select(p.value)` blah
For statistic
, it's showing c(t = -1.860813)
, while for p.value
it is showing 0.07939414
.
Is this difference expected? Because as far as I can see, both have same data type.
currently getting
blah c(t = -1.86081346748685) blah 0.0793941401873582 blah
expected option 1 (both shown as vector)
blah c(t = -1.86081346748685) blah c(p = 0.0793941401873582) blah
expected option 2 (both shown as scalar)
blah -1.86081346748685 blah 0.0793941401873582 blah
Or, anything that'll be same for both.
Does this expectation make sense?