在 R-Studio 中使用语法颜色打印 [英] Print with syntax color in R-Studio

查看:45
本文介绍了在 R-Studio 中使用语法颜色打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 R 中,我总是喜欢打印出脚本,因为它提供了一个很好的概述,并且可以调整最终的错误.我喜欢 R-Studio 中的语法突出显示,因为它有助于阅读和快速理解代码.

In R I always like to print out the script since it gives a good overview and one can adjust eventual errors. I like the syntax highlighting in R-Studio because it facilitates reading and fast comprehension of code.

有没有办法打印出我在编辑器中看到的突出显示的文本?

Is there a way to print out the text with the highlighting I see in the editor?

推荐答案

RStudio 不会以彩色打印,但很容易将代码保存为 PDF;在这种情况下,保留了语法格式.我最喜欢的包是 knitr.

RStudio will not print in colour, but it's easy to save the code as a PDF; in this case the syntax format is preserved. My favourite package is knitr.

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

默认输出为 .tex 格式的 PDF/标记.如果您不想排版,运行以下命令将导出为 .html

The default output is PDF/Markup in .tex. If you prefer not to typeset, running the below will export as .html

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

这篇关于在 R-Studio 中使用语法颜色打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆