Take the 2-minute tour ×

I am using RStudio because I find that it is a good IDE.

I'm starting to feel the need to go through packges code to deeper understanding or hack certains functions. When I try to navigate using Using Ctrl+Click with the mouse For functions defined within packages the code is displayed in a special Source Viewer.

The problem of this view

  1. It is read only view(why?). You can't go to through the code of functions called and defined else. I know other IDE (for other languages) where we can go through the code recursively in read only-mode.
  2. For generic function , we have only the UseMethod line without the code.

My solution was is to load the package(code source) and to go through the code using the Find in files option.

Do you have more efficient method to go respectively through the code? I am open to suggestions: other IDE? Windows/unix? network solution: Do you think it is possible to install Rstudio server version on the cloud to go through all R package without loading?

PS : My question is mainly about going through the code not hacking it.

share|improve this question
Using traceback() to check what functions have actually been called from a generic function might help you with number 2. –  Marius Dec 3 '12 at 5:38
I just go through the source code with my favorite text browser. Package source code is available on CRAN (and elsewhere), and R can be reached from the R-project size. If I want to change a function, I make a new .R file, copy/paste the function, modify it and source that. This keeps things tidy, which is probably why RStudio doesn't enable you to edit the source of functions on the fly. –  Roman Luštrik Dec 3 '12 at 9:46
@RomanLuštrik I totally agree. What if one project requires hack x, and another hack y, do they collide or not? –  Paul Hiemstra Dec 3 '12 at 12:08
Frankly, I would recommend against hacking existing packages, for the reasons already provided, as well as the fact that (most) packages have been pretty carefully constructed. If there's some enhancement you want, best approach is to write a wrapper function. Second best is to write the package maintainer and request the enhancement :-). –  Carl Witthoft Dec 3 '12 at 12:33
For issue 1: F2 (an alternative to Ctrl + click) successfully enters the (read-only) source of functions recursively. However, instead of opening the function's source in a new tab, as happens with the function's source at the first level, it shows the source in the same tab. You can then navigate up again using the back button (just above the source pane) or by pressing Ctrl + F9 (an unwieldy shortcut, I know). –  jbaums Jan 25 '13 at 5:10

2 Answers 2

I generally find github to be the best way to dig into packages (for those posted there). While this is far from a perfect solution, it often also includes the tests and links to additional documentation that you don't always find with the standard "?". This approach is generally most useful if you need to truly grok a package, rather than simply understanding a poorly documented signature. Hadley Wickham's lubridate is a package where this approach paid off for me. Additionally, I find I get a better sense of the quality of the code from examining the tests and ancillary files.

share|improve this answer
+1! thanks! I use github-technique also. But it is not easy to navigate through function definition. I think the best solution is to have a remote IDE( something like Rstudio Server) which is connected to Github (or any other R repository) to get access to all R packages. –  agstudy Apr 20 '13 at 14:24

Put the cursor on the function and press 'F2'. This is equivalent to the 'F3' of Eclipse

share|improve this answer
Welcome to SO. Is is great to have you here under the R tag :) F2 is good to inspect code but it fails with S3method and internal function code. You can see jbaums comment under my question, it says the same with more details. –  agstudy Mar 7 at 12:15

Your Answer


