parameters
parameters copied to clipboard
What's making print_md() work outside a loop and then not work in a loop?
If I use print_md() in an Rmd document to be knitted to PDF, it works just fine (the rendered table looks like beautiful latex output), until I use it in a loop. Then unpredictable things can happen, but it's usually just the un-pretty console output. Below is a reprex:
library(tidyverse) library(parameters)
lm( cty ~ manufacturer, data = mpg ) %>% model_parameters() %>% print_md(caption = "City miles")
mpg %>% select(cty,hwy) %>% names() %>% map(.f = function(response){ lm( formula(str_c(response," ~ manufacturer")), data = mpg ) %>% model_parameters() %>% print_md(caption = response) })
Using print_md() inside purrr::map() prints out un-pretty console-esque tables in PDF.
Is there a fix for this or something I'm not doing right?
I couldn't make it work with purrr::map()
but here's an example that works with a for
loop:
---
output: rmarkdown::pdf_document
---
```{r}
library(tidyverse)
library(parameters)
lm(
cty ~ manufacturer,
data = mpg
) %>%
model_parameters() %>%
print_md(caption = "City miles")
```
```{r results='asis'}
tmp <- mpg %>%
select(cty, hwy) %>%
names() %>%
map(.f = function(response) {
lm(
formula(str_c(response, " ~ manufacturer")),
data = mpg
) %>%
model_parameters()
})
for (i in tmp) {
print(print_md(i))
}
```
Wow that’s great thank you!
On Mon, Jul 25, 2022 at 2:56 AM Etienne Bacher @.***> wrote:
I couldn't make it work with purrr::map() but here's an example that works with a for loop:
---output: rmarkdown::pdf_document---
library(tidyverse) library(parameters) lm( cty ~ manufacturer, data = mpg ) %>% model_parameters() %>% print_md(caption = "City miles")``` ```{r results='asis'}tmp <- mpg %>% select(cty, hwy) %>% names() %>% map(.f = function(response) { lm( formula(str_c(response, " ~ manufacturer")), data = mpg ) %>% model_parameters() }) for (i in tmp) { print(print_md(i)) }``` — Reply to this email directly, view it on GitHub <https://github.com/easystats/parameters/issues/749#issuecomment-1193712361>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AWGYUPA25XUSI7EVW7QZRBLVVZCDDANCNFSM54MVJBWA> . You are receiving this because you authored the thread.Message ID: ***@***.***>
Does this solve your issue and can we close this, or is there still something we could address?
I guess just one other thing I'm struggling to understand is how to add table captions in the loop. I've tried this but it doesn't work:
tmp_captions <- mpg %>%
select(cty, hwy) %>%
names() %>% str_c(" miles")
tmp <- mpg %>%
select(cty, hwy) %>%
names() %>%
map(.f = function(response) {
lm(
formula(str_c(response, " ~ manufacturer")),
data = mpg
) %>%
model_parameters()
})
for (i in tmp) {
print(print_md(i),caption = tmp_captions[i])
}
On Sun, Aug 14, 2022 at 3:02 AM Daniel @.***> wrote:
Does this solve your issue and can we close this, or is there still something we could address?
— Reply to this email directly, view it on GitHub https://github.com/easystats/parameters/issues/749#issuecomment-1214306801, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWGYUPH6V4UCFH6A3HOPD2TVZCRXPANCNFSM54MVJBWA . You are receiving this because you authored the thread.Message ID: @.***>