1

I would like to perform a line-by-line review of code written using RStudio.

I have two questions:

  1. How do I export the script file as a PDF/text file?
  2. How do I make sure that the exported script file includes the line numbers?

Thanks!

** Update: Considering that I wasn't trying to write a report straight from the R/RStudio interface, I realized I could easily open and print the code using Notepad ++. So, here's to remembering a software that most folks probably use for their coding anyway.

cct10
  • 27
  • 1
  • 4
  • After a similar question a while ago I looked in to writing a general command line tool to do just that (source code to PDF) with [libharu](http://libharu.org/). ... It's not *that* hard to quickly get something useful - I think I gave up when adding multilingual code highlighting – Jongware May 27 '15 at 21:03

2 Answers2

1

I found the answer to a similar question that I had for writing a script to a text file here https://statisticsglobe.com/r-save-all-console-input-output-to-file and wanted to share for others facing the same dilemma. Unfortunately, this method does not write out the line numbers though.

# Writing currently opened R script to file

fout = "filpath/filename.txt"

cat(readChar(rstudioapi::getSourceEditorContext()$path, file.info(rstudioapi::getSourceEditorContext()$path)$size), file = fout)

kwat22
  • 11
  • 1
0

Have you ever heard about Knitr?, and also look at this question.

Community
  • 1
  • 1
SabDeM
  • 7,050
  • 2
  • 25
  • 38
  • Thanks for the response. I know that Knitr can be a bit of a complex rabbit hole. I'll take a look into it, while keeping the thread open in case someone else has a simpler solution. – cct10 May 27 '15 at 16:15