Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-home "Organising your functions" content from r-pkgs #121

jennybc opened this issue Feb 5, 2019 · 0 comments


None yet
1 participant
Copy link

commented Feb 5, 2019

The section "Organising your functions" from the "R code" chapter has been removed, in favour of the treatment of this topic here. However this doesn't seem fully fleshed out here yet. I'm pasting the removed text here, so it can be integrated.

Organising your functions {#r-organising}

While you're free to arrange functions into files as you wish, the two extremes are bad: don't put all functions into one file and don't put each function into its own separate file. (It's OK if some files only contain one function, particularly if the function is large or has a lot of documentation.). File names should be meaningful and end in .R.

# Good

# Bad

Pay attention to capitalization, since you, or some of your collaborators, might be using an operating system with a case-insensitive file system (e.g., Microsoft Windows or OS X). Avoid problems by never using filenames that differ only in capitalisation.

My rule of thumb is that if I can't remember the name of the file where a function lives, I need to either separate the functions into more files or give the file a better name. (Unfortunately you can't use subdirectories inside R/. The next best thing is to use a common prefix, e.g., abc-*.R.).

The arrangement of functions within files is less important if you master two important RStudio keyboard shortcuts that let you jump to the definition of a function:

  • Click a function name in code and press F2.

  • Press Ctrl + . then start typing the name:


After navigating to a function using one of these tools, you can go back to where you were by clicking the back arrow at the top-left of the editor


or by pressing Ctrl/Cmd-F9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.