R Markdown suddenly showing output of code

Good morning everyone,

For some reason suddenly my rmarkdown doesnt hide code anymore.

Even when I run the example in RStudio for a Rmarkdown sheet it doesnt show the output correctly.
Please find the example and output below:


> ---
> title: "Untitled"
> output: html_document
> date: "2024-09-23"
> ---
> 
> ```{r setup, include=FALSE}
> knitr::opts_chunk$set(echo = TRUE)
> ```
> 
> ## R Markdown
> 
> This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
> 
> When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
> 
> ```{r cars}
> summary(cars)
> ```
> 
> ## Including Plots
> 
> You can also embed plots, for example:
> 
> ```{r pressure, echo=FALSE}
> plot(pressure)
> ```
> 
> Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

Output:

Anyone has any idea what could be the issue?

Thank you!

This is strange. I cannot reproduce it. Is it possible that you have something in your workspace that is interfering?

My copy of your code:

---
title: "Untitled"
output: html_document
date: "2024-09-23"
---

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

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}
plot(pressure)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

Thank you very much for checking. I cleaned again my workspace (no packages loaded) and I am still getting the issue....

Anyone else has an idea what it could be? I started recently. I didnt do any update or anything different.

Thank you!!

The way it is shown in your screenshot seems to indicate that something is not right in your source document and the code cells are not seen as code cells, or are just not knitted at all.

How do you render your document ? How to do you create the pdf ?

rmarkdown::render() should run your code cell to tranform them using knitr . From your screenshot, it seems like knitr has not run at all.

It is not that it is showing output code. It is showing the source document syntax, which means nothing except for knitr processing.

You should check all this.

Thank you for your message.

I prese the button "knit" and then "knit to pdf" as I have always done & it always worked.

The source document is the Rmarkdown example shown above, but also my Rmarkdowns (which worked in the past) have this issue now..

Someone has any idea?

What is the log message you get ?

Does calling ˋrmarkdow::render()` on the document give the same result ?

Thank you for your reply.

I get the following when running it via console:

rmarkdown::render()
Error in xfun::file_ext(input) :
argument "input" is missing, with no default

Render tab gives this info:

/usr/lib/rstudio-server/bin/quarto/bin/tools/pandoc +RTS -K512m -RTS test.pdf --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output test.pdf --lua-filter /home/...../R/x86_64-pc-linux-gnu-library/4.1/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /home/..../R/x86_64-pc-linux-gnu-library/4.1/rmarkdown/rmarkdown/lua/latex-div.lua --embed-resources --standalone --highlight-style tango --pdf-engine pdflatex --variable graphics --variable 'geometry:margin=1in'

thank you!

My advice included "on the document", this means you need to call rmarkdown::render(<your file path here>)

Please to read the documentation of the tool you are using, this is helpful so that we can efficiently help with limited back and forth.

This gives you the hint that the input is indeed missing.

On which file opened in source pane did you get this log output ? I am not sure why input file is test.pdf which is the same as --output

This puzzles me :thinking:

To be clear, when clicking Render to PDF button on a Rmd source I get this log

==> rmarkdown::render('C:/Users/chris/Documents/test.Rmd',  encoding = 'UTF-8');
++ Activating rlang global_entrace

  |.................                                          |  29% [setup]   

processing file: test.Rmd
                                                                                                     
"C:/Users/chris/scoop/shims/pandoc" +RTS -K512m -RTS test.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output test.tex --lua-filter "C:\Users\chris\AppData\Local\R\win-library\4.3\rmarkdown\rmarkdown\lua\pagebreak.lua" --lua-filter "C:\Users\chris\AppData\Local\R\win-library\4.3\rmarkdown\rmarkdown\lua\latex-div.lua" --embed-resources --standalone --highlight-style tango --pdf-engine pdflatex --variable graphics --variable "geometry:margin=1in" 
output file: test.knit.md


Output created: test.pdf

and it works fine for me I get the code chunk rendered.

In you case, you see you have test.pdf and not test.knit.md so somehow pandoc is not running on the correct document. Something is indeed not right.

Please do share a complete example of what you are doing. Thanks

1 Like

Thank you for your message. I think I have solved the issue. I was not in a project. Once I moved it to a project and re-run it, it worked.

Ok. Not sure what the effect of it. It should not matter. I edited my message above with more information of the possible problem.

1 Like

Okay thank you very much for your help.
I found another post online of someone having issues when not being inside a project. I dont quite understand it as well, but it worked (for now).

1 Like

This topic was automatically closed 7 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.