Code does not include the output in the Knitted Document

Whenever I run code in an R Markdown file it runs code and shows the outputs (histogram, boxplot, tables, console, etc.) but whenever I go to knit the document to HTML, PDF, or Word it does not display the outputs. How do I make it so that the outputs appear in the new HTML, PDF, or Word documents?

Hello @LEK ,

please check that you installed at least the packages rmarkdown and knitr.
If not yet installed then do this. E.g. for knitr:

install.packages('knitr', dependencies = TRUE)

Let us know which warnings and error messages (if any) you see.

And as a last tip to let us help you solve the issue:
send us the whole contents of the Rmd file (you are sure that your input is an Rmd file ?) in your answer by copying it between two pairs of four backticks ("`") in the following way:

````
here your copy of the Rmd file
````

I have installed packages rmarkdown and knitr as well as a few others used in my project. Here is my current code.

---
title: "2.22.22 T6"
author: "LEK"
date: "2/22/2022"
output: word_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r Reading Code}
library(dplyr)
ecls=read.table("ecls200.txt",header=TRUE)
ecls$p1disabl=recode(ecls$p1disabl, "1"="Disability","2"="No Disability")
table(ecls$p1disabl)
```

```{r Histogram}
library(ggplot2)
ggplot(ecls,aes(x=c1rrscal))+
  geom_histogram(aes(y=..density..),colour=1,binwidth=2.5,fill="white")+
  geom_density()+facet_grid(p1disabl~.)+xlab("Reading Test Score")+
  ylab("Frequency")+
  ggtitle("Standardized Scores Among Disabled and Not Disabled Kindergarteners")
```

```{r Boxplot}
library(ggplot2)
ggplot(ecls, aes(x=p1disabl, y=c1rrscal)) + 
geom_boxplot(width=.5) +
coord_flip()+xlab("Reading Test Score")+ylab("Frequency")+
  ggtitle("Standardized Scores Among Disabled and Not Disabled Kindergarteners")
```

```{r Welch's T-Test}
t.test(c1rrscal~p1disabl,data=ecls, var.equal=F)
```

```{r Wilcoxon Rank-Sum Test}
w=wilcox.test(c1rrscal~p1disabl,data=ecls,conf.int=T)
w
```

```{r Generating Mean and Median}
ecls %>% group_by(p1disabl) %>% summarize(mean=mean(c1rrscal),
                                          median=median(c1rrscal))
```

Hello @LEK ,
When I try to knit your Rmd file I get errors because of the names of your chunks.
These names should be one single word without quotes.
E.g. change "Welch's T-Test" in e.g. "Welchs_T-Test" .
When I correct these names it looks like the knitting is starting well
(but then I get an error on the text file that I don't have of course).

So correct the chunk names and let us know if you encounter more errors.

Thank you for the tip. Hopefully this code will work for you

---
title: "2.22.22 T6"
author: "LEK"
date: "2/22/2022"
output: word_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r Reading_Code}
library(dplyr)
ecls=read.table("ecls200.txt",header=TRUE)
ecls$p1disabl=recode(ecls$p1disabl, "1"="Disability","2"="No Disability")
table(ecls$p1disabl)
```

```{r Histogram}
library(ggplot2)
ggplot(ecls,aes(x=c1rrscal))+
  geom_histogram(aes(y=..density..),colour=1,binwidth=2.5,fill="white")+
  geom_density()+facet_grid(p1disabl~.)+xlab("Reading Test Score")+
  ylab("Frequency")+
  ggtitle("Standardized Scores Among Disabled and Not Disabled Kindergarteners")
```

```{r Boxplot}
library(ggplot2)
ggplot(ecls, aes(x=p1disabl, y=c1rrscal)) + 
geom_boxplot(width=.5) +
coord_flip()+xlab("Reading Test Score")+ylab("Frequency")+
  ggtitle("Standardized Scores Among Disabled and Not Disabled Kindergarteners")
```

```{r Welch's_T-Test}
t.test(c1rrscal~p1disabl,data=ecls, var.equal=F)
```

```{r Wilcoxon_Rank-Sum_Test}
w=wilcox.test(c1rrscal~p1disabl,data=ecls,conf.int=T)
w
```

```{r Generating_Mean_and_Median}
ecls %>% group_by(p1disabl) %>% summarize(mean=mean(c1rrscal),
                                          median=median(c1rrscal))
```

Hello @LEK ,

I do not understand why you say "Hopefully this code will work for you".
You did not try to run the code yourself? When you did I should expect that you would see
the error message in the render panel in RStudio:

processing file: LEK.Rmd
(*) NOTE: I saw chunk options "Welch's_T-Test"
please go to Options - Chunk options and package options - Yihui Xie | 谢益辉
(it is likely that you forgot to quote "character" options)
Error in parse(text = code, keep.source = FALSE) :
:1:15: unexpected symbol
1: alist( 'Welch's_T
^
Calls: ... parse_params -> withCallingHandlers -> eval -> parse_only -> parse
Execution halted

You still have the quote in chunkname for the Welch's T-Test . Remove it.
The easiest way to avoid these problems is by using names without spaces and quotes.

I understand that you want to give your sections well readable identifications.
For that I would use the (sub-) title facility by using one or more "#" in the text (outside the code chunk).
As an example:


### Welch's T-Test
In this section blabla ...

```{r Welch_T-Test}
t.test(c1rrscal~p1disabl,data=ecls, var.equal=F)
```

Full example below with:

  • your code
  • corrected chunknames
  • added subtitle (for Welch test only)
  • an ecls table generated by me (instead of the one read from txt file)

In the resulting word-file I see that the plots will have to be fine-tuned :cry:

---
title: "2.22.22 T6"
author: "LEK"
date: "2/22/2022"
output: word_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r Reading_Code}
library(dplyr)
#ecls=read.table("ecls200.txt",header=TRUE) 
set.seed(2022)
ecls = data.frame(
  p1disabl = rep(c(1,2),times=3),
  c1rrscal = runif(6)
)

ecls$p1disabl=recode(ecls$p1disabl, "1"="Disability","2"="No Disability")
table(ecls$p1disabl)
```

```{r Histogram}
library(ggplot2)
ggplot(ecls,aes(x=c1rrscal))+
  geom_histogram(aes(y=..density..),colour=1,binwidth=2.5,fill="white")+
  geom_density()+facet_grid(p1disabl~.)+xlab("Reading Test Score")+
  ylab("Frequency")+
  ggtitle("Standardized Scores Among Disabled and Not Disabled Kindergarteners")
```

```{r Boxplot}
library(ggplot2)
ggplot(ecls, aes(x=p1disabl, y=c1rrscal)) + 
geom_boxplot(width=.5) +
coord_flip()+xlab("Reading Test Score")+ylab("Frequency")+
  ggtitle("Standardized Scores Among Disabled and Not Disabled Kindergarteners")
```

# Welch's T-Test
In this section blabla ...

```{r Welch_T-Test}
t.test(c1rrscal~p1disabl,data=ecls, var.equal=F)
```

```{r Wilcoxon_Rank-Sum_Test}
w=wilcox.test(c1rrscal~p1disabl,data=ecls,conf.int=T)
w
```

```{r Generating_Mean_and_Median}
ecls %>% group_by(p1disabl) %>% summarize(mean=mean(c1rrscal),
                                          median=median(c1rrscal))
```
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.