Notepad ++ not recognizing R language - r

I was reviewing a .rmd file of a colleague for an R script today and realized the style functionality was not working. I am new to this way of R coding and so wanted it in what I am used to reading and so renamed the script a .r so that the style functionality would be enabled.
The style format appeared but then I realized at some point it was no longer working again. Now I can't get Notepad++ to recognize my R scripts (those with a .r in the file naming convention) and can't figure out why.
Should R be a choice in the language selection drop down menu?
When I go to -> Settings -> Style Configurator the recent Style is selected but the colors for the comments (for instance) don't match. They should be green and they are not. I am using Notepadd++ 6.5.5. I would update but our IT department makes it very difficult to do this.

Remove R key from REBOL section in the file ‘langs.xml’ (path: user\AppData\Roaming\Notepad++\langs.xml )
Line 301 by default is:
<Language name=“rebol” ext=" r reb" commentLine=";" commentStart="" commentEnd="">
The messed up part is ext=" r reb". It should just say ext=“reb”
Change that, save the file and you are all set.
See:
https://notepad-plus-plus.org/community/topic/14363/r-file-association-messed-up

1.Check if checkbox Enable Global foreground colour is off in settings -> -> Style Configurator -> global stylers -> global override .
2.Try changing color theme.
3.Check R's lang syntax colors in Style Configurator.

Related

Is it possible to interact with elements of the RStudio IDE itself using R code?

Is it possible to interact with the RStudio application using R code inside it? I mean interactions like opening a file in a card, creating a tab for a new unsaved file or changing some text inside an opened tab.
I know a very similar thing can be obtained by just simply creating a new text file or changing its content with R but this way it doesn't interact anyway with the RStudio app itself.
Some context: I was thinking of a tool that could automate inserting some reprexes / snippets of code which could work as a line of code that, when run from a file, replaces itself with a block of code or make a new unsaved file tab and put some code inside it. And yes, I know a very similar thing can be achieved other ways (e.g. simply copying the intended code block into the clipboard) but I'm curious and exploring the possibilities.
Thanks to the link provided by Konrad Rudolph I managed to find the answer myself.
There is a package called rstudioapi built into the RStudio that allows many different functionalities and doesn't require using plugins or addins.
All the features can be found in the official manual.
Opening a new unsaved file tab with some code in it can be obtained by running:
rstudioapi::documentNew(
"example code here",
type = "r",
position = rstudioapi::document_position(0, 0),
execute = FALSE
)
Inserting code can be easily done with insertText(text = "") which inserts text at the current position of the text cursor.
Changing one line into another can be obtained with the combination of getActiveDocumentContext(), which returns among others the document content and the selection range which is basically equivalent to the cursor position. Then the changing itself can be done with modifyRange() respectively to the cursor position and/or the document content.
That allows many possibilities including for example some smoother automation of the workflow.

customise R help files - font colouring

I'm wondering is it possible to customise R help files so that certain text is colour coded and easier to read. rdoc already does this except that it sends the output to the console. I would instead, like it to be sent to the help panel (i'm using Rstudio). Is there any workaround for this?
If we run ?lm normally, we can see the usual help file in the help panel on the right below but when you do it again after using rdoc in Rstudio we get the help file colour coded which is great but its sent to the console output (left side). Ideally, we would like it to remain on display in the help panel as we are running code. The way it is now - it disappears the minute you run something.
?lm
#devtools::install_github("mdequeljoe/rdoc")
library(rdoc)
options(rdoc.by_section = FALSE)
rdoc(lm)
I want to put the code into my .rprofile similar to #csgillespie .rprofile. Note, if you follow his code you can use ?lm instead of having to call rdoc(lm) directly to produce the colour coded console output.
I have a feeling this can't be done easily (if at all?) but interested to hear any suggestions.
Thanks
This is possible, but a little involved. You'll need your own css file defined to do it, though it would be possible to create a function that writes appropriate css.
As a proof of concept, I have used a copy of the "R.css" file defined inside every package's "/html" folder, and just changed the h2 color to red, with the file saved locally as "my.css".
Anyway, once you have the css file, this function will show the appropriate help file with the appropriate styling in your R viewer window:
help_css <- function(func, css_file)
{
pack <- sub("^.*:(.*)>$", "\\1", capture.output(environment(func)))
func <- deparse(substitute(func))
x <- readLines(paste0(find.package(pack), "/html/", func, ".html"))
x[3] <- paste("<style>",
paste(readLines(css_file), collapse = "\n"),
"</style>")
writeLines(x, file.path(tempdir(), "test.html"))
myViewer <- getOption("viewer")
myViewer(file.path(tempdir(), "test.html"))
}
So, for example, if I do:
help_css(lm, "my.css")
I get:
As of RStudio v1.2 you can style RStudio's integrated help pane by creating a custom user theme (essentially an .rstheme file).
I've given help pane styling a try in extending the rscodeio theme (without colored syntax highlighting, though). The latest CSS code is found here.
The help pane styling is currently only available in the optional Tomorrow Night Bright (rscodeio) editor theme.
To use it right away, you can either
install the current rscodeio master branch using remotes:
remotes::install_github("anthonynorth/rscodeio")
And then activating the editor theme named Tomorrow Night Bright (rscodeio) under Tools → Global Options… → Appearance → Editor theme. A first attempt of the help pane CSS code is included.
or – recommended – install my fork's interim-merge branch which contains all my latest work[1] overhauling the package, including a new apply_theme parameter to activate the desired editor theme right away:
remotes::install_github("salim-b/rscodeio#interim-merge")
rscodeio::install_themes(apply_theme = "Tomorrow Night Bright (rscodeio)")
[1]: This has also been proposed upstream a while ago (1, 2) but I haven't heard back from the author since.
The result looks as follows (example for ?pal::as_string):

Multimarkdown in GitHub's Atom editor - made a start, want to make more progress

To extend the basic Markdown support in Atom, I've converted the TextMate Multimarkdown bundle (unescaping one hash sign - see the process on this Atom discussion). The (converted) TextMate bundle files are now in my Atom config folder.
Markdown syntax now highlights okay (and differently from the built-in GitHub Markdown) when I choose 'Multimarkdown' from the syntax list. The table sytnax appears to pick out table heads, but there's no preview and no support for definition lists.
Can someone point me to the file(s) in Atom I'd need to work on to get:
a preview pane?
syntax highlighting for definition lists?

Change default code highlight in Sphinx documentation

I'm writing a small R guide with Sphinx.
The default code highlighting language is Python, so I have to add at the beginning of the file .. highlight:: r in order to set R as the default code language.
Is there a way to change this option in the conf.py file?
I tried to edit pygments_style = 'sphinx' but without success..
Have you tried to set the conf.py var :
highlight_language = 'r'
(or 'R' ?)
https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-highlight_language
However I don't see R language support in Pygments language list http://pygments.org/languages/

How to disable spell checking in code regions in RMD files (Markdown, knitr, R)

I am using the Vim-R-plugin to edit files containing markdown and R-code blocks such that the files can be complied using knitr. The filetype is: RMD. I have enabled spell checking. How can I disable the spell checking within the code blocks?
Spell checking is attached to certain syntax groups. Find the :syn region that covers the R code blocks, and append / edit in contains=#NoSpell.
Instead of trying to get the #NoSpell working by region, my approach is to toggle between languages.
I work in three languages which are set up to toggle with a function key where I include "nospell". This makes turning spellchecking on and off as easy as pressingt F7. When coding and writing nospell is turned on, when finalizing the edits I toggle to the appropriate language.
In fact, I find spellchecks in my code to be a plus. I make mistakes in the comment sections too, sometimes even in variable names/plot lables etc. This way you have a quick last check of all language items that are going to be visible .
I got this to work on OS X by editing the ~/.vim/syntax/R.vim and doing a search and replace of all instances of #Spell to #NoSpell. Then restarting vim. All the red underscores were gone from the code chunks but were still in the rest of the the rmarkdown.
Interestingly this has not effected the spell checking in pure R documents that have a .R extension, so I having thought I understood what I was doing perhaps I have to admit I don't fully. But at least it has turned off spell checking of the code chunks in rmarkdown (Rmd) documents while leaving it still working elsewhere in the document.

Resources