Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exuberant Ctags with R

Tags:

Is there any documented use of ctags with R? Would this be useful? Would it be difficult to implement?

Specifically, I've just started using Vim. It would be cool to be able to write an R function in one file, use the function in another file (e.g., an Rnw file, test file, or some other script), and be able to use Ctrl+] to navigate to the function source.

Update: I've since stumbled on the rtags function. It is suggested below that it works with vim.

like image 275
Jeromy Anglim Avatar asked Jan 25 '11 14:01

Jeromy Anglim


People also ask

What is exuberant ctags?

Exuberant Ctags is a multilanguage reimplementation of the Unix ctags utility. Ctags generates an index of source code definitions which is used by numerous editors and utilities to instantly locate the definitions.

What is a ctags file?

Ctags is a programming tool that generates an index (or tag) file of names found in source and header files of various programming languages to aid code comprehension. Depending on the language, functions, variables, class members, macros and so on may be indexed.

What is ctags Linux?

The ctags command creates a tags file for use with the ex and vi editors from the specified C, Pascal, FORTRAN, yacc, lex, and LISP source files. The tags file consists of locators of programming language specific objects (such as functions and type definitions) within the source files.


1 Answers

This is a modification of Henrico's answer, and may be implemented by copying and pasting the following code into one's ~/.ctags files. Henrico's code did not work for indented functions, but the following code does.

--langdef=R
--langmap=r:.R.r
--regex-R=/^[ \t]*"?([.A-Za-z][.A-Za-z0-9_]*)"?[ \t]*<-[ \t]function/\1/f,Functions/
--regex-R=/^"?([.A-Za-z][.A-Za-z0-9_]*)"?[ \t]*<-[ \t][^f][^u][^n][^c][^t][^i][^o][^n]/\1/g,GlobalVars/ 
--regex-R=/[ \t]"?([.A-Za-z][.A-Za-z0-9_]*)"?[ \t]*<-[ \t][^f][^u][^n][^c][^t][^i][^o][^n]/\1/v,FunctionVariables/

This allows variables to be recognized with ctags as well as functions. If you're using the taglist vim addon, then, it allows you to distinguish between global variables and other variables. Also, if you're using taglist, then you will need to paste the following in your vimrc.

let tlist_r_settings = 'R;f:Functions;g:GlobalVariables;v:FunctionVariables'
like image 186
LMZ Avatar answered Sep 28 '22 07:09

LMZ