adafdwwf
adafdwwf

Reputation: 162

Rmarkdown: how to save the current output and show the code but do not run it?

the codes in rmarkdown is:

rnorm(1)

Assume the result is 0.23. I want to save this 0.23 to my word document.

After cache=TRUE was set, the result every time I knit to word is the same but not equal to the current output 0.23.

How do I fix the current output and knit it to word?

Please do not use set.seed(). Because the rnorm is just a simple example for a procedure which has different outputs every time it runs and set.seed may not work.

Please do not cite variables in rmarkdown to fix an output.Citing does't work when the output in rmarkdown can't be cited such as a summary in a model. And all you have is a summary output and you can't cite it. In lm(linearmodel) you can cite every element in it while in many other models there is no such attributes thus you can't cite.

So fixing the current output is very important. Is it possible in rmarkdown?

Upvotes: 0

Views: 3251

Answers (1)

g_t_m
g_t_m

Reputation: 714

I may be oversimplifying this, but is something like the following .Rmd not what you're after?

---
title: "Saving RNorm"
author: "John Doe"
date: "3 January 2019"
output: word_document
---

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

## Setting the value

```{r}
random <- rnorm(1)

plot(random)
```

## Using the value

As you can see in the chart above, the random number I produced is `r random`.

You can assign your random value to a variable, use it in whatever analysis or plot you need to, and then cite it in the text body by wrapping it in back quotes (prefixed with r).

The output this produces is below.

RMarkdown Microsoft Word example

Upvotes: 1

Related Questions