The current state of R support in Atom

introduction

This is a guide to the current state of R support in Atom. I’m not writing this as an expert on Atom, merely as a user.

This guide is geared towards Mac as I do not have experience on either Linux or Windows.

All of these packages can be installed with the Atom package manager either via commandline (apm install) or in the GUI (Preferences → Install).

With all of these packages, don’t forget to take a look at the command palette (cmd-shift-p) which will give you quick access to commands both bound and unbound to keys.

DISCLAIMER: I am the maintainer of r-exec.

syntax highlighting

standard R files

The syntax highlighting for *.R files is quite good and support is built into the language-r package. It builds basic syntax highlighting and was originally ported from the r.tmbundle TextMate package. There hasn’t been much activity on the GitHub repository as of late, but I think the package is quite stable so there isn’t too much work to be done (in terms of basic functionality). I have been using it without any major issues for at least a year.

R Markdown

Early 2016 I added very crude support in language-gfm for R markdown blocks. This will give you standard functionality out of the box (language-gfm is a base package), however, it is a bit clunky. Earlier this year language-markdown added very good support, and in my opinion, is a much better package all around for editing all sorts of Markdown files. The biggest benefit of language-markdown over language-gfm for editing Rmd is proper syntax parsing of decorators. An example is {r eval=TRUE} parses nicely and a typo like {r eva=TRUE} would be obvious (see image below).

Example of language-markdown parsing syntactically (in)correct Rmd decorators

Rnw

As far as I can tell, there really isn’t any good syntax highlighting for LaTeX style Rnw knitr files in Atom. But with the ease of R Markdown, unless you are writing a lot of math, I would suggest against using Rnw anyway. I have looked at adding support for it and it doesn’t seem like too much work. However, I have little incentive since I don’t really write Rnw. If you are interested in picking up this project, let me know and I might be able to guide you a little bit.

autocompletion

The Atom autocompletion engine (autocomplete-plus, bundled with Atom) is quite good and has providers for many languages including R support which is relatively recent. Without the specific R support autocomplete-plus, (bundled with Atom) does a decent job at finding text within your buffers and auto completing it. Installing autocomplete-R will give you more elaborate autocompletion of built-in R functions along with their arguments. The author has expressed interest in providing this functionality for other packages as well.

The image below showcases this functionality:

Example of autocomplete-R

running code

Personally, my workflow includes using iTerm2 for remote execution of code, along with RStudio server, and sometimes locally executing code in R.app. As far as I know, the only package with capability to send code to all of these applications in Atom is r-exec. It is simple to configure which application you are sending code to (either in the Packages menu or type cmd-shift-p and begin typing r exec to see a list of options).

r-exec has the ability to send the current line, paragraph, function, and RMarkdown block. It also has additional features to jump to the next logical block (line, paragraph, etc.) after a command has been sent.
Recently, support for ‘smart’ insertion of operators (currently assignment and the pipe operator) has been implemented. This means if there is whitespace on the left or right of the cursor, it will not insert additional whitespace when an operator has been inserted via the operator shortcut.

In the near future I plan adding support for internal Atom terminals (e.g. Term3). I also plan to add support for building RMarkdown internally. If others can help, it would be great to get support on Linux and Windows.

There are also other packages that are available for executing code which I have no experience with but I am sure others use:

  • hydrogen which adds in-line support for Jupyter notebooks (Python, Julia).
  • build-rscript which will run Rscript on a R file.

navigating code

Atom has a pretty good ctags engine, atom-ctags. Matching rules for tags have to be specified in a file before you can begin using it with R. Some guidance on this can be found here.
After the tags have been built for a specific project, you can jump between symbols using ctrl-option-down when the cursor is above a specific symbol.

static code analysis (linting)

Linting can be done using the linter-lintr package. It uses the popular R linter lintr and has pretty standard warning/error reporting in the Atom ‘gutter’.

The figure below (pulled from the lintr website) displays the functionality nicely:

example of lintr

summary and links

Advertisement

12 comments

  1. GambleBKB

    I just discovered Juno, a package that transforms Atom into an IDE for Julia.
    Something similar for R would be great.
    In R community pretty much anyone is stuck with RStudio (which is not open source) and I don’t like not having options.

      • henne87

        @Kyle:
        I try to use Hydrogen with IRKernel but also IPython. The last weeks I worked in RStudio using Rmarkdown. Rmarkdown worked much better for me than Jupyter because the conversion to hmtl/word/pdf worked very nice. However, I would rather like to code in Atom + I cannot work with Python in rstudio (you cannot access variables from previous code chunks in Rstudio). With hydrogen in Atom this works.

        So, now I can use a e.g. a .md document and insert code chunks from both Python and R or just one of them.

        The problem I run into are the following:
        1. Autocompletion does not work well in the .md file compared to in a .py or a .R file in Atom.
        2. If I end up with a document with markdown and R code chunks or Python chunks, how can make it look just as nice as knitr in Rstudio manages to do?

        Can you maybe help me out here?

  2. Jacob Fiksel

    I just made a package to support R indentation rules in Atom–mainly lining up function arguments with the opening parenthesis (which had mostly already been done for Python code), as well as piping together dplyr commands using %>% and piping ggplot2 functions with +. The repo is here–https://github.com/jfiksel/r-indent–and it would be awesome to have your thoughts/contributions, since I’ve never coded in javascript before. I also think it would be great to have a package where the “Knit” command would automatically tell the command line to implement the knit function for that file in R.

  3. Evan

    You can also use the atom-shell-commands (https://atom.io/packages/atom-shell-commands) package to make knitting documents easy from within Atom. I used the following entry in my config file with success:

    “atom-shell-commands”:
    commands: [
    {
    name: “knitRmd”
    command: “/usr/bin/R”
    arguments: [
    “-e”
    “rmarkdown::render(‘{FileName}’)”
    ]
    options:
    save: true
    cwd: “{FileDir}”
    keymap: “ctrl-2”
    }
    ]

    • henne87

      Evan, so do you create an .rmd file from within Atom and then you use this command and get the same output as when you would click on knitr? Can u refer me to a source where it is explained how to use knitr in Atom?

  4. Pingback: PRINCIPAIS IDE’S para R |

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s