In a recent post I explored how to enable CTags support for the Kate text editor. This post contains a self-contained explanation of how to also enable CTags for writing R code. When developing R code, we would like to have Ctags support in in the R environment rkward that uses kate as its editor, rather than just in “vanilla” kate. Note that by the time of writing this post, this functionality is only included in the development version of rkward, not the official latest release.1

Install CTags

CTags has to be installed on the local machine, on Ubuntu for example as follows:

$ sudo apt install exuberant-ctags

Adding CTags support for the R language

By default, CTags does not include support for the R language, which can however can be added by the user. To enable R support, we can add the following lines to a file “.ctags” in the home directory (if it does not exist, create it):

--langdef=R
--langmap=r:.R.r
--regex-R=/^[ \t]*"?([.A-Za-z][.A-Za-z0-9_]*)"?[ \t]*(<-|=)[ \t]function/\1/f,Functions/

(I got this from Fong Chun Chan’s blog here.

Activate the CTags plugin in rkward

Now, there should be a CTags button at the botton of the main rkward window (next to “R Console”, “Help Search” etc.). Click the button and go to “Index targets”. Here, you can click “+ Add” to add the directory that should be indexed by CTags. This has to be done for each directory where we work with R files. However, I think this works recursively, so if you index the upper most directory, all of the directories within are indexed as well. Do not forget to “update index” when you have added a new function.

Define keybindings

I think in R, the important actions are “Go To Definition” to jump to a function definition (I use CTRL-Y) and “Jump back one step” (I use CTRL-Q).

Last words

When using CTags in rkward, one of the main advantages of RStudio over rkward (for me) disappears, because I can now also use rkward to jump between functions across files. CTags even seems to be faster than RStudio function hopping. Moreover, in rkward I profit from the excellent Kate editor and the awesome document preview for R Markdown documents.


Last updated: 2020-11-06

Back to the front page

 


  1. The development version can be installed on Ubuntu by adding an inofficial repository as described here, or by installing from source, using the latest code from the KDE Gitlab.