36

is there a way to list ToDo comments in rstudio?
Before I used eclipse and really loved to put some # TODO I definitely need more unit tests here! comments in my source code.

I could not find this feature in rStudio so far and I was wondering, if there is something like a plugin or maybe an easy way of searching such comments.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
drmariod
  • 11,106
  • 16
  • 64
  • 110
  • 1
    Why not directly asking to RStudio? https://support.rstudio.com/hc/en-us –  Aug 07 '15 at 09:26
  • 1
    Thanks for the link. I checked and two years ago, already some people asked for it. It looks like nothing changed since now. I am wondering, how other user deal with these things. I think it is pretty common in other IDEs. There is no plugin system in rstudio, is there? – drmariod Aug 07 '15 at 09:33
  • Why don't you use `Ctrl+Shift+C` to insert comment you call `TODO`, then `Ctrl+F` to find `TODO`? –  Aug 07 '15 at 09:40
  • 2
    Nice suggestion, but might be a bit difficult in package development with 20 files. I might go with my command line solution `find . -type f -name '*.R' -exec grep -Hni 'todo' {} \;` but I thought there might be better solutions... – drmariod Aug 07 '15 at 09:43
  • 2
    Use ctrl-shift-R (or cmd-shift-R on OS X) to insert a "section" comment which should show up in the RStudio function selector popup. Stick "TODO" in there and it shld be easy to find in-file. – hrbrmstr Aug 07 '15 at 09:50
  • 2
    Just installed RStudio version 1.1.423 and it looks like they've implemented a feature that changes the text color of 'TODO' and 'FIXME' keywords in code comments. – Brian D Feb 23 '18 at 20:38

4 Answers4

18

There is no such system in RStudio, but there is an easy way of searching for the comments. Do this:

  1. Go to Edit -> Find in Files
  2. Tick the checkbox "Regular Expression"
  3. Enter the following regular expression: ^\s*# TODO
  4. Click Find

That regular expression will match any line that starts with # TODO.

Jonathan
  • 8,497
  • 41
  • 35
  • Uh wow, haven't seen this option before... Great, I also can click the file name and also directly the lines where the comment is... Almost perfect! :-) Thanks for this hint. – drmariod Aug 12 '15 at 06:49
  • It's odd that RStudio uses special syntax highlighting for #TODO yet doesn't seem to have any other built in functionality around them. – jzadra May 19 '20 at 23:33
  • Actually, you don't need the regular expression (regex) [only if you really want to show results in which the search is starting a line]. And if you use the regex described above, you'll loose the possibility to add the comment anywhere, e.g. after another comment. In fact, I would not even include the #. Just find in files, TODO or FIXME :-) – Aleix Apr 25 '23 at 14:47
18

I would suggest that you consider the todor RStudio add-in by dokato. After installing via devtools:

devtools::install_github("dokato/todor")

You will be able to conveniently list ToDo items across your project:

sourcing

Official example

(images and code sourced from: https://github.com/dokato/todor)

Konrad
  • 17,740
  • 16
  • 106
  • 167
  • Thanks for that comment. I vaguely remember reading that it will be implemented in rStudio in the near future anyways, together with some other keywords like `FIXME` or so... But I couldn't find the article at the moment. I will have a look into the package, but so far the `find in files` is very convenient. :-) – drmariod Mar 29 '18 at 05:52
10

You can use the outline list by having:

# TODO I definitely need more unit tests here! ####

Just keep in mind that you have to have 4 '#' at the end of the line

Fabian
  • 101
  • 1
  • 2
  • 1
    thanks, that's how i use it too. In case this is relevant for anybody else, it's possible to use four dashes `-` as an alternative to the four hashtags – icj Jan 03 '20 at 19:16
3

If you work with git and the files are tracked you can use

git grep TODO

in the terminal (which is also included in the Rstudio IDE) to get a list of your TODOs.

andschar
  • 3,504
  • 2
  • 27
  • 35