R - load_all()并添加一个新的函数文件

时间:2016-01-05 10:32:04

标签: r devtools

我是R的新手,需要在现有软件包中添加新的函数文件。对于编程和测试,我使用load_all()(来自devtools pkg)来获得原始的R文件。我编写了我的函数并将其保存在与(原始)R文件的其余部分相同的目录中。 但是现在当我执行load_all()时,执行此函数!我不知道为什么。我在这里做错了什么?

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    
}

0 个答案:

没有答案