QAsena
QAsena

Reputation: 641

How can I hide code blocks in xaringan presentation?

I'm running some plot code in markdown to generate a plot in a xaringan presentation. The code works but is a little long and so takes up the whole presentation slide forcing the actual plot off the edge (see img).

How can I hide the code block generating the plot?

Also how can I compress the code block with a scroll bar?

output

```{r}
r_exp.fun <- function(r = 0.05, N_pop = 10, t = 150)
{
  N <- vector("numeric", length = t)
  N[1] <- N_pop
  for (i in 2:t)
  {
    N[i] <- N[i-1] + (N[i-1] * r)
  }
  return(N)
}

args_list <- list(0.045, 0.055, 0.06)

matplot(
  mapply(
    r_exp.fun,
    r = args_list
  )
  ,type = "l")
abline(h = list(7052, 29150, 59000))
```

The alternative is of course to save as an image but if possible I would prefer to be able keep the code as a resource for anyone with the link.

Thanks!

Upvotes: 0

Views: 968

Answers (1)

jkrainer
jkrainer

Reputation: 423

As alistaire already mentioned in the comments, RMarkdown has various chunk options to customize the output. For your problem the option echo needs to be set to FALSE.

The other options (from https://rmarkdown.rstudio.com/lesson-3.html):

include = FALSE 

prevents code and results from appearing in the finished file. R Markdown still runs the code in the chunk, and the results can be used by other chunks.

echo = FALSE 

prevents code, but not the results from appearing in the finished file. This is a useful way to embed figures.

message = FALSE 

prevents messages that are generated by code from appearing in the finished file.

warning = FALSE 

prevents warnings that are generated by code from appearing in the finished.

fig.cap = "..." 

adds a caption to graphical results.

Upvotes: 5

Related Questions