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 515959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:40:55+00:00 2026-05-13T07:40:55+00:00

so I decided I would put my few R functions into a package and

  • 0

so I decided I would put my few R functions into a package and I’m reading/learning Writing R Extension.

it obviously complains about an amount of things I’m not doing right.

after enough googling, I’m firing a few questions here, this one is about testing style: I am using RUnit and I like having tests as close possible to the code being tested. this way I won’t forget about the tests and I use the tests as part of the technical documentation.

for example:

fillInTheBlanks <- function(S) {
  ## NA in S are replaced with observed values

  ## accepts a vector possibly holding NA values and returns a vector
  ## where all observed values are carried forward and the first is
  ## carried backward.  cfr na.locf from zoo library.
  L <- !is.na(S)
  c(S[L][1], S[L])[1 + cumsum(L)]
}

test.fillInTheBlanks <- function() {
  checkEquals(fillInTheBlanks(c(1, NA, NA, 2, 3, NA, 4)), c(1, 1, 1, 2, 3, 3, 4))
  checkEquals(fillInTheBlanks(c(1, 2, 3, 4)), c(1, 2, 3, 4))
  checkEquals(fillInTheBlanks(c(NA, NA, 2, 3, NA, 4)), c(2, 2, 2, 3, 3, 4))
}

but R CMD check issues NOTE lines, like this one:

test.fillInTheBlanks: no visible global function definition for
  ‘checkEquals’

and it complains about me not documenting the test functions.

I don’t really want to add documentation for the test functions and I definitely would prefer not having to add a dependency to the RUnit package.

how do you think I should look at this issue?

  • 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-13T07:40:56+00:00Added an answer on May 13, 2026 at 7:40 am

    Where are you putting your unit tests? You may not want to put them into the R directory. A more standard approach is to put them under inst\unitTests. Have a look at this R-wiki page regarding the configuration.

    Alternatively, you can specify what files will be exported in your NAMESPACE, and by extension, what functions should and should not be documented.

    Beyond that, ideally you should have your tests run when R CMD CHECK is called; that’s part of the design. In which case, you should create a test script to call your tests in a separate tests directory. And you will need to load the RUnit package in that script (but you don’t need to make it a dependency of your package).

    Edit 1:

    Regarding your failure because it can’t find the checkEquals function: I would change you function to be like this:

    test.fillInTheBlanks <- function() {
      require(RUnit)
      checkEquals(fillInTheBlanks(c(1, NA, NA, 2, 3, NA, 4)), c(1, 1, 1, 2, 3, 3, 4))
      checkEquals(fillInTheBlanks(c(1, 2, 3, 4)), c(1, 2, 3, 4))
      checkEquals(fillInTheBlanks(c(NA, NA, 2, 3, NA, 4)), c(2, 2, 2, 3, 3, 4))
    }
    

    That way the package is loaded when the function is called or it will inform the user that the package is required.

    Edit 2:

    From “Writing R Extensions”:

    Note that all user-level objects in a package should be documented; if a package pkg contains user-level objects which are for “internal” use only, it should provide a file pkg-internal.Rd which documents all such objects, and clearly states that these are not meant to be called by the user. See e.g. the sources for package grid in the R distribution for an example. Note that packages which use internal objects extensively should hide those objects in a name space, when they do not need to be documented (see Package name spaces).

    You can use the pkg-internal.Rd file as one option, but if you intend on having many hidden objects, this is usually handled in the declarations in the NAMESPACE.

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

Sidebar

Related Questions

I'm editing some Python code with rather long functions and decided it would be
Because ObjectContext.SaveChanges() occurs within a transaction I decided it would be best for my
I've decided that it would be good for me to move outside of my
I've decided to use this.variableName when referring to string/int etc.. fields. Would that include
Decided to use Apache's Common Configuration package to parse an XML File. I decided
would like to put fieldSets side-by-side on my Edit page because I have so
I had a boss, past-tense, who decided to put svn branches in the same
I am working on an ASP.NET MVC3 app. I was reading about good Javascript
I've decided to put all my constants in a neat class called constants, and
In an effort to brush up on some multithreading/sorting fun, I decided to put

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.