WARNING: You should check out kiendang/rdocsyntax
instead.
It's faster and integrates better with RStudio.
This package enables syntax highlighting for R HTML documentation.
Syntax highlighting follows RStudio theme when running RStudio, otherwise uses Textmate theme.
SOME CAVEATS
- You might notice the highlighted doc is displayed inside RStudio Viewer pane instead of Help pane. This is a limitation. Thus things like forward, backward, ... are unavailable. You should check out
kiendang/rdocsyntax
instead for those features. It also has the advantage of being faster.
Install the package
# install.packages("devtools")
devtools::install_github("kiendang/rdocsyntax.ex")
Enable syntax highlighting
rdocsyntax.ex::highlight_html_docs()
If using outside RStudio, set help_type
to html
to automatically display doc in HTML mode. Otherwise ?
syntax won't work, use help(..., help_type = "html")
instead.
options(help_type = "html")
Enjoy R docs with colorful code
?sapply
# or help(sapply, help_type = "html")
Disable syntax highlighting
rdocsyntax.ex::unhighlight_html_docs()
There are ## Not run
code examples that are single line. e.g in ?rstudioapi::highlightUi
## Not run: rstudioapi::highlightUi("#rstudio_workbench_panel_git")
The code will not be syntax-highlighted because the whole line is considered a comment.
The solution we use is to turn it into
## Not run:
rstudioapi::highlightUi("#rstudio_workbench_panel_git")
in the generated html.