Rmarkdown: how to show output and codes but do not run the codes?












0















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.










share|improve this question























  • 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


















0















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.










share|improve this question























  • 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
















0












0








0








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.










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 14:04









adafdwwfadafdwwf

697




697













  • 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





















  • 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



















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














1 Answer
1






active

oldest

votes


















0














In principle you could solve the issue in 2 ways:




  1. 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 option knitr::opts_chunk$set(cache.extra = knitr::rand_seed). Read more here: https://yihui.name/knitr/demo/cache/#reproducibility-with-rng


  2. Make 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)







share|improve this answer


























  • 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











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
});


}
});














draft saved

draft discarded


















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









0














In principle you could solve the issue in 2 ways:




  1. 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 option knitr::opts_chunk$set(cache.extra = knitr::rand_seed). Read more here: https://yihui.name/knitr/demo/cache/#reproducibility-with-rng


  2. Make 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)







share|improve this answer


























  • 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
















0














In principle you could solve the issue in 2 ways:




  1. 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 option knitr::opts_chunk$set(cache.extra = knitr::rand_seed). Read more here: https://yihui.name/knitr/demo/cache/#reproducibility-with-rng


  2. Make 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)







share|improve this answer


























  • 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














0












0








0







In principle you could solve the issue in 2 ways:




  1. 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 option knitr::opts_chunk$set(cache.extra = knitr::rand_seed). Read more here: https://yihui.name/knitr/demo/cache/#reproducibility-with-rng


  2. Make 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)







share|improve this answer















In principle you could solve the issue in 2 ways:




  1. 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 option knitr::opts_chunk$set(cache.extra = knitr::rand_seed). Read more here: https://yihui.name/knitr/demo/cache/#reproducibility-with-rng


  2. Make 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)








share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 2 at 15:10

























answered Jan 2 at 14:57









JozefJozef

1,076510




1,076510













  • 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



















  • 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

















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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]