1

Beginner question here so sorry if it's an obvious mistake. I've produced a table of summary statistics using the summary_table function from the R package qwraps2. When I run the code in markdown it produces the table as expected but when I try and knit the rmd to html to publish on rpubs it looks as follows:

## |Summary Statistics               |ESS (N = 73)                    |
## |:--------------------------------|:-------------------------------|
## |**Alcohol drunk at the weekend** |                      |
## |   variable            |interval                        |

and so on...

(the table should look like these tables: https://cran.r-project.org/web/packages/qwraps2/vignettes/summary-statistics.html )

I know I have coded qwraps2_markup to equal 'markdown' but I'm unsure how to create the same table without doing so.

```{r}

options(qwraps2_markup = 'markdown')
our_summary <-
  list("Alcohol drunk at the weekend" = 
         list("variable" =~ c("interval"),
              "min" = ~ min(ESS$alcwknd),
              "median" = ~ median(ESS$alcwknd),
              "max" = ~ max(ESS$alcwknd),
              "mean (sd)" = ~ qwraps2::mean_sd(ESS$cgtsday)),
       "Cigarettes smoked" =
         list("variable" =~ c("interval"),
              "min" = ~ min(ESS$cgtsday),
              "median" = ~ median(ESS$cgtsday),
              "max" = ~ max(ESS$cgtsday),
              "mean (sd)" = ~ qwraps2::mean_sd(ESS$cgtsday)),
       "Age" = 
         list("variable" =~ c("Interval"),
              "min" = ~ min(ESS$agea),
              "median" = ~ median(ESS$agea),
              "max" = ~ max(ESS$agea),
              "mean (sd)" = ~ qwraps2::mean_sd(ESS$agea)),
       "Time helping others" =
         list("variable" =~ c("Ratio"),
              "mode" =~ time_mode),
        "Felt Depressed" =
         list("variable" =~ c("Ordinal"),
              "mode" =~ dpr_mode),
       "Main Activity" =
         list("variable" =~ c("Categorical"),
              "mode" =~ act_mode))


tab <- summary_table(ESS, our_summary)
print(tab, rtitle = "Summary Statistics")
```

Any help is much appreciated and thanks in advance.

Peter
  • 7,460
  • 2
  • 47
  • 68

1 Answers1

1

As noted in the comments under the question the resolution for this problem is setting the correct code chunk options for knitr. The default in knitr is to report the results of a code chunk with results = 'markup' which results in the output looking like the R console. results = "asis" will "write raw results from R into the output document" which means placing markdown into a .Rmd or latex into a .tex file.

```{r, results = "asis"}

options(qwraps2_markup = 'markdown')
our_summary <-
  list("Alcohol drunk at the weekend" = 
         list("variable" =~ c("interval"),
              "min" = ~ min(ESS$alcwknd),
              "median" = ~ median(ESS$alcwknd),
              "max" = ~ max(ESS$alcwknd),
              "mean (sd)" = ~ qwraps2::mean_sd(ESS$cgtsday)),
       "Cigarettes smoked" =
         list("variable" =~ c("interval"),
              "min" = ~ min(ESS$cgtsday),
              "median" = ~ median(ESS$cgtsday),
              "max" = ~ max(ESS$cgtsday),
              "mean (sd)" = ~ qwraps2::mean_sd(ESS$cgtsday)),
       "Age" = 
         list("variable" =~ c("Interval"),
              "min" = ~ min(ESS$agea),
              "median" = ~ median(ESS$agea),
              "max" = ~ max(ESS$agea),
              "mean (sd)" = ~ qwraps2::mean_sd(ESS$agea)),
       "Time helping others" =
         list("variable" =~ c("Ratio"),
              "mode" =~ time_mode),
        "Felt Depressed" =
         list("variable" =~ c("Ordinal"),
              "mode" =~ dpr_mode),
       "Main Activity" =
         list("variable" =~ c("Categorical"),
              "mode" =~ act_mode))


tab <- summary_table(ESS, our_summary)
print(tab, rtitle = "Summary Statistics")
```
Peter
  • 7,460
  • 2
  • 47
  • 68