cct10
cct10

Reputation: 27

How to export script as PDF/text with line numbers in R?

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.

Upvotes: 1

Views: 5095

Answers (2)

kwat22
kwat22

Reputation: 11

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)

Upvotes: 1

SabDeM
SabDeM

Reputation: 7190

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

Upvotes: 0

Related Questions