Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4114900
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:30:50+00:00 2026-05-20T22:30:50+00:00

Background I written an R package, and now a collaborator (recent CS grad who

  • 0

Background

I written an R package, and now a collaborator (recent CS grad who is new to R) is editing and refactoring the code. In the process, he is dividing up my functions into smaller, more generic functions.

What he is doing makes sense, but when I started with package.skeleton(), I had one file per function. Now, he has added functions on which the primary function depends, but that may have limited use outside the function itself.

He suggests that all the functions go into a single file, but I am against that because it is easier to do version control when we work on different files.

I have since started using roxygen to document each function within the text.

Question

What is the recommended way to handle functions: clearly the helper functions should stay with the the main function, but to what extent do I need to document helper functions?

The @export suggestion in the comments is helpful, but I am curious to know how others organize their code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T22:30:50+00:00Added an answer on May 20, 2026 at 10:30 pm

    I cut up my functions under two conditions :

    1. when it improves readibility of the code of the main function, and/or
    2. when it avoids copy-pasting code, eg if the same code is used a couple of times within the same function.

    I do include the so-called helper functions in the file of the main function, but only as long as those helper functions are not used in any other function. Actually, I consider them nested within the main function. I do understand your argument for version control, but changing the helper function comes down to changing the performance of the main function, so I see no problem in keeping them in the same file.

    Some helper functions might be used in different other functions, and then I save them in their own file. Often I do export those functions, as they might be of interest for the user. Compare this to eg lm and the underlying lm.fit, where advanced users could make decent use of lm.fit for speeding up code etc.

    I use the naming convention used in quite some packages (and derived from linux), by preceding every “hidden” function by a dot. So that makes

    .helper.function <- function(x, ...){
        ... some code ...
    }
    
    main.function <- function(x, ...){
        ...some code, including .helper.function(y, ...)
    }
    

    I explicitly @export all functions that need exporting, never the helper functions. It’s not always easy to judge whether a function might be of interest to an end user, but in most cases it’s pretty clear.

    To give an example : A few lines of code to cut off NA lines I consider a helper function. A more complex function to convert the dataset to the correct format I export and document.

    YMMV

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've written some code that should make a new image. My background image has
Background: I've written a pair of .NET functions for AES encryption/decryption. I want to
Background: We have an XML document containing thousands of pseudocode functions. I've written a
I have written an app which plays background music with MediaPlayer. I am now
Background: I've written a multi-threaded application in Win32, which I start from C# code
My problem is that I have written code in Visual C# for a background
Background: I've written this before but I don't like the approach. The reason is
Background: I have written a java swing based client server application. The server is
I have written a application which runs in the background. I want to write
I've written a simple KShell script to kick off a background task #/bin/ksh #startMonitoring

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.