0

I have created a function in R called calibrate, with the following call:

calibrate<-function(prior, p1=NULL, p2=NULL, p3=NULL, q13, q23, 
          accuracy=1e-7, sol=4, data, name_col=1, pval_col=2, tier_col=NULL)

The first thing that occurs in this function is:

  if(!is.null(tier_col))
  {
    work<-as.data.frame(table(data[tier_col]))

    p1<-work[,2][work[1]==1]
    p2<-work[,2][work[1]==2]
    p3<-work[,2][work[1]==3]
  }

A lot of other things happen after this, but the function isn't getting past this.

The call that I am making is:

calibrate(prior=0.10, q13=3, q23=2, accuracy=1e-7, sol=4, 
      data=read.csv("C:/Users/C191131/Desktop/calibrate_test.csv"),
      name_col=1, pval_col=2, tier_col=3)

where the data file has 3 columns, one for name, one for pvalue, and one for tier. As you can see, tier_col is being set to 3 and then immediately when entering the function, it should be checked to see if it is null.

When I make the call, I get the following error:

Error in calibrate(prior = 0.1, q13 = 3, q23 = 2, accuracy = 1e-07, sol = 4,  : 
      unused argument (tier_col = 3)

I don't understand how this can be happening, since the first thing I do when entering the function is call upon the tier_col variable.

Any help/ideas? I have researched this error to no avail.

Thanks!!

  • 3
    Are you sure you spelled everything correctly? That error doesn't mean that you aren't using the parameter in the function, it means that that you called a function with a parameter it didn't understand. For example, you can get the same error with `ff<-function() 5; ff(a=3)`. Check `args(calibrate)` to be sure the parameter is there. – MrFlick Jul 11 '14 at 14:45
  • Hmm... when I check `args(calibrate)` after sourcing the function, I get `function (prior, p1, p2, p3, q13, q23, accuracy = 1e-07, sol = 4, data, name_col = 1, pval_col = 2, tier_col=NULL)`. Once calling the function wiht tier_col (it should be able to be called in two ways, with `tier_col` or with `p1`, `p2`, and `p3`), I have no issue. Once I call it without `tier_col` the error occurs and that variable does not come up when I check `args(calibrate)`. – hockeyvic06 Jul 15 '14 at 13:31
  • So it seems that once I call the function differently (with `p1`, `p2`, and `p3` instead of `tier_col`) that I can never change back to running it with `tier_col`. Thoughts? – hockeyvic06 Jul 15 '14 at 13:34
  • This signature of the function (what you see when you call `args()`) should never change. The only way it can change is if you somewhere redefine `calibrate<-`. So it sounds like you may have two definition of the calibrate function somewhere and are accidentally overwriting the one you want. – MrFlick Jul 15 '14 at 13:51
  • Thanks MrFlick... didn't realize I was referencing an old version of my function that didn't have this defined. Got it figured out and now `args(calibrate)` gives me the same thing all of the time. – hockeyvic06 Jul 25 '14 at 16:54

0 Answers0