The ‘Introducing NppToR: R Interaction for Notepad++’ article from the 2010-1 issue.
A good practice when programming or doing analysis in R is to keep the commands in a script that can be saved and reused. An appropriate editor makes programming in R much more efficient and less error prone.
On Linux/Unix systems, users typically use either Vim or EMACS with ESS. Both of these have features to improve programming in R. Features like syntax highlighting, which means certain keywords are colored or marked to indicate they have special meaning, and code folding, where lines of code can be automatically grouped and temporarily hidden from view. Perhaps the most important feature is the ability to directly evaluate lines of code in the R interpreter. This facilitates quick and easy programming while maintaining a solid record in a reusable script.
The version of R for Microsoft Windows comes with a built in editor. This editor does have the interaction features like VIM and EMACS, but lacks the other features like syntax highlighting and code folding. There are several alternative code editors for Windows, such as Notepad++, WinEDT, Tinn-R, and Eclipse, that do possess advanced features but many novice users are simply unaware of them.
NppToR is a native windows solution that brings the advantages that users of other platforms have to Windows users. NppToR works with the powerful and popular code editor Notepad++ (http://notepad-plus.sourceforge.net/). Notepad++ has a natural windows feel to it and so the learning curve for getting started is almost nonexistent, but as users become more accustomed to the advanced features of Notepad++ the real power comes out.
NppToR tries to follow the easy use and low learning curve of Notepad++. It not only simply works, but also becomes more powerful as users become more familiar with it’s features. NppToR has been under development for over a year and has gained a serious user base without ever being promoted outside of the R mailing lists. NppToR can be downloaded from SourceForge (http://sourceforge.net/projects/npptor/).
The primary purpose of NppToR is to add R interaction capability to Notepad++. It does this through the use of hotkeys. When the hotkey is pressed it triggers an action such as evaluating a line of code. Figure 1 lists the hotkeys and what action they perform. The hotkeys are totally configurable through the settings.
NppToR Default Hotkeys and Actions
F8
Evaluate a line of code or selection.
Ctrl+F8
Evaluate the entire current file.
Shift+F8
Evaluate the file to the point of the cursor.
Ctrl+Alt+F8
Evaluate as a batch file and examine the results.
NppToR sits in in the system tray, as shown in Figure 2. The menu, where the settings and extra features are found, is accessed by right clicking on the NppToR icon in the system tray.
One of the ways that NppToR just works is that when evaluating code from
Notepad++, NppToR looks for a current open R GUI session in which to
evaluate the code. If R is not running, a new R session will be started
and the code evaluated there. The R home directory is automatically
found through the windows registry. One advantage of having NppToR
starting R is that the working directory for R is set to the directory
of the open script in Notepad++. This means that file names for data
files and other scripts can be made relative rather than absolute. For
example, if the script reads in a data file data.txt
and the data file
is in the same directory as the script the file reference can simply be
made as
<- read.table("data.txt") data
rather than using the absolute path,
<- read.table("C:/path/to/data.txt") data
which is not only longer than necessary to type but not portable either. Simply moving a file or renaming a folder could break all the file references. For already open R sessions there is a menu item that will set the working directory to the current script directory.
NppToR is designed to be very small and non-intrusive. It is designed to sit in the background and is only active when Notepad++ is in use. Occasional users of R may not like having the utility running on startup; for those users when NppToR is run manually it will also launch Notepad++.
Although Notepad++ now has native support for the R language, it is a recent addition. NppToR also generates syntax files for use with Notepad++’s user defined language system, which is an artifact from when Notepad++ did not have support for R. This feature has been retained because it still offers advantages over the built in syntax rules. For example, NppToR generates the syntax files dynamically, and can take advantage of a library to include the keywords from installed packages. This method ensures that all major keywords are highlighted, and can easily be updated to possible changes in the R distribution, as well as the addition of new packages. The generated language differs also in enforcing case sensitivity and proper word boundaries.
R is an ideal environment for performing simulation studies. These simulations can run for a long time, and are typically run in the batch mode. NppToR not only provides an easy hotkey to run these simulations but also provides a simulation monitor to keep track of active simulations, monitor how long they have been running and provide an easy way to terminate those that need to be stopped early. Figure 3 shows the simulation monitor.
Notepad++ benefits from a large user base, and is constantly updated and improved, including several extensions that also help with developing for R. Notepad++ with NppToR mirrors the advantages of editors on other platforms but with a native windows feel. The power and strength of NppToR comes in its simplicity. It enhances an already powerful editor to become a superior editor for R.
Both Notepad++ and NppToR are easy to use and easy to learn, but as users become proficient with the vast array of keyboard commands and the macro system the true power of Notepad++ is revealed. NppToR should be considered by any who work with R on Windows.
The author’s research was supported by a grant from the National Cancer Institute (CA57030).
This article is converted from a Legacy LaTeX article using the texor package. The pdf version is the official version. To report a problem with the html, refer to CONTRIBUTE on the R Journal homepage.
Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".
For attribution, please cite this work as
Redd, "Introducing NppToR: R Interaction for Notepad++", The R Journal, 2010
BibTeX citation
@article{RJ-2010-1-npp, author = {Redd, Andrew}, title = {Introducing NppToR: R Interaction for Notepad++}, journal = {The R Journal}, year = {2010}, note = {https://rjournal.github.io/}, volume = {2}, issue = {1}, issn = {2073-4859}, pages = {62-63} }