0

I'm using an rmd to generate a github readme and would like to prevent knitr from creating the .Rhistory file in the working directory.

There's some discussion of how to interactively do this in a prior question:

Disable saving history

But it's not clear how any of those suggestions and answers can be applied to knitr.

Nick
  • 312
  • 1
  • 14
  • AFAIK saving history is a function of your DE and has nothing to do directly with knitr. Are you using knitr from RStudio? Did you test the answers mentioned in the linked question? – jkd Jul 25 '23 at 19:19
  • My incomplete understanding of what's happening is that knitr is calling the engines referenced for each code chunk, so there should be a way to access and edit knitr's call to R, (or python, etc), though how to do that is unclear to me. The DE that is calling knitr i don't think matters in this case. I don't even know if it itself leaves a footprint on it's own Rhistory file. – Nick Jul 27 '23 at 15:02
  • I don't think so. `knitr::knit` is an R function and functions do not append anything of what they do internally to `.Rhistory`. So, depending on how you call `knitr::knit`, nothing or only your call will be appended to `.Rhistory`. – jkd Jul 27 '23 at 16:01
  • It's similar to sourcing an `.R` document, only the `source()` call will be added to your history, not the content of the sourced file. – jkd Jul 27 '23 at 16:02
  • It's not clear that there was a call to knitr made in the `.Rhistory` for the overarching sessions's working directory, but the `.Rhistory` file that gets generated in the directory where the `.Rmd` is knit is only populated by the calls made in the code chunks. – Nick Jul 27 '23 at 20:47
  • How do you call knitr (where from, what is the command)? – jkd Jul 28 '23 at 08:15
  • You can knit the `.Rmd` either through the interactive button on in the menu bar, or through a keyboard shortcut. – Nick Jul 28 '23 at 21:00
  • Yes I am aware what methods there are, what I am asking is which of these did you use. But with either options, nothing gets written to my `.Rhistory`. So again, how did you call `knitr`? Do you have the option from the SO question you linked to disabled? Does the code from your chunks appear in the history even if you do not run the code manually beforehand? – jkd Jul 29 '23 at 09:36

0 Answers0