Rmarkdown: how to show output and codes but do not run the codes?
my problem is quite different from others'. Please read my question again.
The situation is this:
In Rmarkdown, I have this code:
rnorm(1)
Assume the first time I run the chunk I get 0.23, and the output will show in rmarkdwon '0.23', and then I write in my rmarkdown:
Now there is a random number 0.23
After echo=TRUE
was set, then the codes will be executed and both codes and outputs will be showed again. But I don't want to executed it again. At the first time I run the codes I get an output 0.23
. I want to keep this 0.23
'and show the codes and outputs. So the codes should't be run again.
How to fix a output in rmarkdown and show the codes and output but do not run the codes again?
Don't tell me to cite the variable in rmakdown by `varibale`. I know how to cite it and that's not what am asking.
r r-markdown
add a comment |
my problem is quite different from others'. Please read my question again.
The situation is this:
In Rmarkdown, I have this code:
rnorm(1)
Assume the first time I run the chunk I get 0.23, and the output will show in rmarkdwon '0.23', and then I write in my rmarkdown:
Now there is a random number 0.23
After echo=TRUE
was set, then the codes will be executed and both codes and outputs will be showed again. But I don't want to executed it again. At the first time I run the codes I get an output 0.23
. I want to keep this 0.23
'and show the codes and outputs. So the codes should't be run again.
How to fix a output in rmarkdown and show the codes and output but do not run the codes again?
Don't tell me to cite the variable in rmakdown by `varibale`. I know how to cite it and that's not what am asking.
r r-markdown
I think u needcache=T
for that chunck
– jyjek
Jan 2 at 14:06
2
or set.seed("random number"), although to be fair, that doesn't really "fix" the code in a sense...
– Rob
Jan 2 at 14:08
add a comment |
my problem is quite different from others'. Please read my question again.
The situation is this:
In Rmarkdown, I have this code:
rnorm(1)
Assume the first time I run the chunk I get 0.23, and the output will show in rmarkdwon '0.23', and then I write in my rmarkdown:
Now there is a random number 0.23
After echo=TRUE
was set, then the codes will be executed and both codes and outputs will be showed again. But I don't want to executed it again. At the first time I run the codes I get an output 0.23
. I want to keep this 0.23
'and show the codes and outputs. So the codes should't be run again.
How to fix a output in rmarkdown and show the codes and output but do not run the codes again?
Don't tell me to cite the variable in rmakdown by `varibale`. I know how to cite it and that's not what am asking.
r r-markdown
my problem is quite different from others'. Please read my question again.
The situation is this:
In Rmarkdown, I have this code:
rnorm(1)
Assume the first time I run the chunk I get 0.23, and the output will show in rmarkdwon '0.23', and then I write in my rmarkdown:
Now there is a random number 0.23
After echo=TRUE
was set, then the codes will be executed and both codes and outputs will be showed again. But I don't want to executed it again. At the first time I run the codes I get an output 0.23
. I want to keep this 0.23
'and show the codes and outputs. So the codes should't be run again.
How to fix a output in rmarkdown and show the codes and output but do not run the codes again?
Don't tell me to cite the variable in rmakdown by `varibale`. I know how to cite it and that's not what am asking.
r r-markdown
r r-markdown
asked Jan 2 at 14:04
adafdwwfadafdwwf
697
697
I think u needcache=T
for that chunck
– jyjek
Jan 2 at 14:06
2
or set.seed("random number"), although to be fair, that doesn't really "fix" the code in a sense...
– Rob
Jan 2 at 14:08
add a comment |
I think u needcache=T
for that chunck
– jyjek
Jan 2 at 14:06
2
or set.seed("random number"), although to be fair, that doesn't really "fix" the code in a sense...
– Rob
Jan 2 at 14:08
I think u need
cache=T
for that chunck– jyjek
Jan 2 at 14:06
I think u need
cache=T
for that chunck– jyjek
Jan 2 at 14:06
2
2
or set.seed("random number"), although to be fair, that doesn't really "fix" the code in a sense...
– Rob
Jan 2 at 14:08
or set.seed("random number"), although to be fair, that doesn't really "fix" the code in a sense...
– Rob
Jan 2 at 14:08
add a comment |
1 Answer
1
active
oldest
votes
In principle you could solve the issue in 2 ways:
Do not execute the code each time the output is rendered but "remember" the results of some execution of said code and show that one on render. This can be done very easily by adding
cache=TRUE
to your chunk:{r cache=TRUE}
. To make this completely reproducible, you should also include the optionknitr::opts_chunk$set(cache.extra = knitr::rand_seed)
. Read more here: https://yihui.name/knitr/demo/cache/#reproducibility-with-rngMake sure that your code produces reproducible results. In case of generating random numbers this is doable by setting a seed, for example
set.seed(1L)
There is a problem. Aftercache = True
was set, then I choose toknit it to word
. However, the result in the word isn't the same as the current output.
– adafdwwf
Jan 3 at 4:54
How do I keep the current output I see and knit it to word?
– adafdwwf
Jan 3 at 5:07
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54007732%2frmarkdown-how-to-show-output-and-codes-but-do-not-run-the-codes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In principle you could solve the issue in 2 ways:
Do not execute the code each time the output is rendered but "remember" the results of some execution of said code and show that one on render. This can be done very easily by adding
cache=TRUE
to your chunk:{r cache=TRUE}
. To make this completely reproducible, you should also include the optionknitr::opts_chunk$set(cache.extra = knitr::rand_seed)
. Read more here: https://yihui.name/knitr/demo/cache/#reproducibility-with-rngMake sure that your code produces reproducible results. In case of generating random numbers this is doable by setting a seed, for example
set.seed(1L)
There is a problem. Aftercache = True
was set, then I choose toknit it to word
. However, the result in the word isn't the same as the current output.
– adafdwwf
Jan 3 at 4:54
How do I keep the current output I see and knit it to word?
– adafdwwf
Jan 3 at 5:07
add a comment |
In principle you could solve the issue in 2 ways:
Do not execute the code each time the output is rendered but "remember" the results of some execution of said code and show that one on render. This can be done very easily by adding
cache=TRUE
to your chunk:{r cache=TRUE}
. To make this completely reproducible, you should also include the optionknitr::opts_chunk$set(cache.extra = knitr::rand_seed)
. Read more here: https://yihui.name/knitr/demo/cache/#reproducibility-with-rngMake sure that your code produces reproducible results. In case of generating random numbers this is doable by setting a seed, for example
set.seed(1L)
There is a problem. Aftercache = True
was set, then I choose toknit it to word
. However, the result in the word isn't the same as the current output.
– adafdwwf
Jan 3 at 4:54
How do I keep the current output I see and knit it to word?
– adafdwwf
Jan 3 at 5:07
add a comment |
In principle you could solve the issue in 2 ways:
Do not execute the code each time the output is rendered but "remember" the results of some execution of said code and show that one on render. This can be done very easily by adding
cache=TRUE
to your chunk:{r cache=TRUE}
. To make this completely reproducible, you should also include the optionknitr::opts_chunk$set(cache.extra = knitr::rand_seed)
. Read more here: https://yihui.name/knitr/demo/cache/#reproducibility-with-rngMake sure that your code produces reproducible results. In case of generating random numbers this is doable by setting a seed, for example
set.seed(1L)
In principle you could solve the issue in 2 ways:
Do not execute the code each time the output is rendered but "remember" the results of some execution of said code and show that one on render. This can be done very easily by adding
cache=TRUE
to your chunk:{r cache=TRUE}
. To make this completely reproducible, you should also include the optionknitr::opts_chunk$set(cache.extra = knitr::rand_seed)
. Read more here: https://yihui.name/knitr/demo/cache/#reproducibility-with-rngMake sure that your code produces reproducible results. In case of generating random numbers this is doable by setting a seed, for example
set.seed(1L)
edited Jan 2 at 15:10
answered Jan 2 at 14:57
JozefJozef
1,076510
1,076510
There is a problem. Aftercache = True
was set, then I choose toknit it to word
. However, the result in the word isn't the same as the current output.
– adafdwwf
Jan 3 at 4:54
How do I keep the current output I see and knit it to word?
– adafdwwf
Jan 3 at 5:07
add a comment |
There is a problem. Aftercache = True
was set, then I choose toknit it to word
. However, the result in the word isn't the same as the current output.
– adafdwwf
Jan 3 at 4:54
How do I keep the current output I see and knit it to word?
– adafdwwf
Jan 3 at 5:07
There is a problem. After
cache = True
was set, then I choose to knit it to word
. However, the result in the word isn't the same as the current output.– adafdwwf
Jan 3 at 4:54
There is a problem. After
cache = True
was set, then I choose to knit it to word
. However, the result in the word isn't the same as the current output.– adafdwwf
Jan 3 at 4:54
How do I keep the current output I see and knit it to word?
– adafdwwf
Jan 3 at 5:07
How do I keep the current output I see and knit it to word?
– adafdwwf
Jan 3 at 5:07
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54007732%2frmarkdown-how-to-show-output-and-codes-but-do-not-run-the-codes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I think u need
cache=T
for that chunck– jyjek
Jan 2 at 14:06
2
or set.seed("random number"), although to be fair, that doesn't really "fix" the code in a sense...
– Rob
Jan 2 at 14:08