0

I'm new to R and need to add a new function file to an existing package. For the programming and testing I used load_all() (from the devtools pkg) to have the original R files. I wrote my function and saved it in the same directory as the rest of the (original) R files. But now when I do load_all(), this function is executed! I have no idea why. What am I doing wrong here?

library(devtools)

calc_curve<-function(){
CurvePars<-c(0,0)
doMIC<-readline("Do you want to calculate MIC? (y/n) \n")
if(doMIC=="y") 
 {
    CAlb<-readline("Do you want to use C.Albicans/FLC standard curve? (y/n)\n")
     #use the equation we calculated MIC=a*exp(b*Rad). V1=a, V2=b
    if(CAlb=="y")   CurvePars=c(7.17,  -0.129) 
    else
    {
      exFile <- readline("Do you have a standard curve file?  (y/n)\n ")
      if(exFile=="y"){ 
        setwd(getwd())
        curveFile <- tcltk::tk_choose.files(caption = "Select the standard curve data file") ;
        tempPars<-read.table(curveFile, header=FALSE,sep=",",dec=".");
        CurvePars=unlist(tempPars)


        # calculate MIC and add to data file
        }
      else{
        calib<-readline("Do you want to provide data for MIC calibration? (y/n)\n")
        if(calib=="y"){
           MICFile <- tcltk::tk_choose.files(caption = "Select the MIC calibration file") 
           MICdata<- read.csv(MICFile, header=FALSE,sep="\t",dec="."); 
           MIC_length=length(MICdata[[1]])
           R1<-0
           MIC<-0
           for (i in 1:MIC_length)
             {
             R1[i]<-RAD2.df[MICdata[i,1],"RAD20"];
             MIC[i]<-MICdata[i,2]
              }
           fit<-lm(log(MIC)~R1)
           A=summary(fit)$coefficients[1]
           CurvePars<-exp(A)
           B=summary(fit)$coefficients[2]
           CurvePars[2]<-B
           CurveFile <- readline( "How would you like to name the curve file?\n ") 
           # handle the case of a pre-existing file
           #open(File=paste(CurveFile,".csv",sep=""),"w")
           CurveFile=paste(getwd(),"/",CurveFile,".csv",sep="")
           write.table(CurvePars,CurveFile,col.names = FALSE,row.names = FALSE)
          }
        else {CurvePars[1]=0
              CurvePars[2]=0}
      }
    }
  }
 CurvePars    
}
Inbal H
  • 33
  • 1
  • 6
  • if you mean `load_all` from `devtools` package you should mention that, or at least add `devtools` tag to question, otherwise provide source of `load_all` function. – jangorecki Jan 05 '16 at 12:53
  • Thanks for clarifying this. I'm an experienced programmer (in Matlab and C) but very new to R. The whole concept of packages is unfamiliar to me. – Inbal H Jan 05 '16 at 13:40
  • R concept of packages is in some ways quite similar to Linux concept of packages. They are self contained units of code having clearly defined dependencies with a proper namespace managing. I can recommend to read `R CMD build --help`, `R CMD check --help` and `R CMD INSTALL --help`. – jangorecki Jan 05 '16 at 14:14

0 Answers0