0

I would like to execute an R script file to a pdf or word and not have the figures, tables, output, etc. displayed, only the lines of written code.

I tried this:

rmarkdown::render('script.R')

But I need it without the output that is also generated. I am pretty new to R so I am not that familiar with all the options.

shafee
  • 15,566
  • 3
  • 19
  • 47
vossi
  • 81
  • 6
  • 2
    `render()` works for .Rmd files. – Phil Sep 11 '22 at 15:58
  • @vossi Is this guide you to what you want?: https://bookdown.org/yihui/rmarkdown-cookbook/source-script.html – Carlos Luis Rivera Sep 12 '22 at 02:17
  • @CarlosLuisRivera Then I have to first convert the document to an rmd right? Because I cannot run this code in my regular r script. – vossi Sep 12 '22 at 06:27
  • You may first provide a new Rmd file and write a chunk in which `source()` your R script. Then, you can knit the Rmd file. No conversion is required in this process. – Carlos Luis Rivera Sep 12 '22 at 07:12
  • I managed to do that but not I get the error: Error in sink(file, type = type, split = split) : sink stack is full – vossi Sep 12 '22 at 07:16
  • It seems like r starts producing a lot of empty data frames and then crashed but I do not know why it is doing that. @CarlosLuisRivera – vossi Sep 12 '22 at 07:27
  • I do not know either since there is no [minimal working example](https://stackoverflow.com/help/minimal-reproducible-example) and there is no detailed information about the errors... – Carlos Luis Rivera Sep 12 '22 at 07:34
  • Do you have any for-loop-like iteration in your R script? If so, the error related to `sink` might happen due to such a kind of iteration. See https://stackoverflow.com/questions/26296288/how-to-avoid-sink-stack-is-full-error-when-sink-is-used-to-capture-messages and please google more about the error. – Carlos Luis Rivera Sep 12 '22 at 07:41

0 Answers0