Printing using syntax color in R-Studio

In R, I always like to type a script, as it gives a good overview, and possible errors can be corrected. I like the syntax highlighting in R-Studio because it makes it easier to read and quickly understand the code.

Is there a way to print backlit text that I see in the editor?

+6
source share
3 answers

RStudio will not print in color, but it is easy to save the code in PDF format; in this case, the syntax format is saved. My favorite package is a scribe.

library(knitr) stitch("file_name.R") 

The default output is PDF / Markup in .tex. If you prefer not to print, the launch below will be exported as .html

 stitch(script="file_name.R", system.file("misc", "knitr-template.Rhtml", package="knitr")) 
+7
source

This is not a R-Studio solution, but notepad ++ will print the R source with syntax highlighting.

+9
source

Short description

The reason this answer to this question is because of the last line of the question:

Is there a way to print backlit text that I see in the editor?

therefore, we are not limited to the fact that only Rstudio software is used here.

After exploring the amazing answer from @rrg and realizing that it runs the code line by line, I wrote a comment below his answer and continued my search on the Internet. My problem is that the code I wrote is so large, and so the time taken to execute it to get the version selected by the syntax is not possible.

Most online connectivity solutions have notepad ++, which is a Windows application, and I am a separate Linux user, so I was looking for a way I can do this on Linux (and possibly Mac)

How I decided it:

Inspired by a blog post , I used the famous and beloved Vim to convert R to syntax highlighted by HTML, and then because you can open HTML in your browser you can do anything with it (print, screenshot, etc.).

  • Enable syntax highlighting in Vim:

    • open terminal
    • then open the vim configuration file by typing vim ~/.vimrc
    • press i from the keyboard to switch to insert mode
    • go to the end of the file using the arrow keys on the keyboard.
    • type syntax on at the end of the file
    • Now you need to save and exit. To do this, you need to press the Esc button on the keyboard to exit the "insert" mode, and then type :x and press Enter to save and close the file.
    • if you want to change the syntax highlighting color scheme, visit the bottom of this website
  • From the terminal, open the file using Vim:

     vim YOUR_FILE_PATH 
  • When you open the R-code in vim, you can include line numbers if you want by pressing Esc , and then type :set number and press Enter .

  • To convert R to HTML, press Esc to make sure you are not in paste mode, and then type :TOhtml and press Enter . This will result in a broken window in the terminal, half your R code and the other half your new HTML code.

  • To save the files, type :x along with the Enter button from the keyboard twice to save both files (your R file will not change if you did not type anything extra in it, and your HTML file will be created with the same name next to your R-code )

  • Now open it with your favorite browser (in my case Vivaldi) and do whatever you want (in my case, convert all HTML to PNG)

0
source

All Articles