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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:38:08+00:00 2026-05-22T01:38:08+00:00

Much of my work revolves around diagnostic tests for tuberculosis. As you might imagine,

  • 0

Much of my work revolves around diagnostic tests for tuberculosis. As you might imagine, it’s handy to be able to quickly evaluate and validate the outputs of those tests. I wrote a function that does just that, here (pared down for clarity). In short, it takes the numeric results from the test and produces the manufacturer-specified interpretation.

This function works well for me – I’ve validated it against thousands of tests, and it’s fast enough for anything I throw at it. I’d like to bundle it and a couple of similar functions into a package for wider use, however, and I’d like to get some feedback on it before I do so:

  1. The function depends on a great big for loop wrapped around nested if-else functions. It isn’t especially elegant and the dread for() undoubtedly damages my credibility with some (ahem), but it works. Is there a better approach to this? If so, is it sufficiently better to warrant re-writing Code That Works?

  2. The criteria in the above function are for interpretation of the test in North America; the rest of the world follows slightly different standards. I’d like to have those available, as well. I’m considering having a separate, non-exported function for each. The various data checks (excluded from the above gist) would continue to live in the main function, which would then call the specified subfunction. Does that sound reasonable?

  3. Any other suggestions or advice? Style, code organization – anything at all.

I realize I should probably just push this baby bird out of the nest, but I work mostly in a vacuum and so am a bit nervous. Any advice is greatly appreciated.

Edit: in case you missed the link to the gist, this is the function I’m talking about.


As requested, sample test data.

  • 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-22T01:38:09+00:00Added an answer on May 22, 2026 at 1:38 am

    Edited to reflect comments and to validate against test data

    You can avoid any type of loop or if altogether and simply use R vector subscripting:

    qft.interp <- function(nil, tb, mitogen, tbnil.cutoff = 0.35){
    
      # Set a tolerance to avoid floating point comparison troubles.
      tol <- .Machine$double.eps ^ 0.5
    
      # Set up the results vector
      result <- rep(NA, times = length(nil))
      result[nil+tol > 8.0] <- "Indeterminate"
      result[is.na(result) & (tb-nil+tol > tbnil.cutoff) & 
              (tb-nil+tol > .25*nil)] <- "Positive"
      result[is.na(result) & (tb-nil+tol < tbnil.cutoff | tb-nil+tol < .25*nil) &
            !(mitogen-nil+tol < 0.5)] <- "Negative"
      result[is.na(result) & ((tb-nil+tol < tbnil.cutoff | tb-nil+tol < .25*nil) &
              mitogen-nil+tol < 0.5)] <- "Indeterminate"
      result
    }
    
    all(with(tests, qft.interp(nil, tb, mitogen)) == tests$interp)
    
    [1] TRUE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use Json2Csharp.com all the time. Saves me so much work. Is there a
Update: Last night, I decided that this is just too much work to change
Consider the apps that large blogs have (which work pretty much like an RSS
This is driving me crazy and has resulted in lost work (not much, at
I've spent too much time trying to get this to work on IE 7.
I haven't worked much with Nexus before, so I'm still trying to work out
The subject pretty much says it all. How does the meta:resourcekey attribute work, and
I use git for my local work (and love it ever so much), and
I can't get my progress bar to work. Any help is much appreciated! Here's
A long time ago, when my company was much smaller, dividing the development work

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.