Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
146 views
in Technique[技术] by (71.8m points)

R CMD Check Errors on Examples, Examples Work

I don't have as much computer science experience so I'm a bit overwhelmed! I have an R package that is already released on the CRAN. It passed its CMD checks and worked fine, but I made a change. It is a Gibbs sampler, so I had it output quantile based CIs, but I changed it to HPD. But now it's failing it's CMD checks and I don't know why. The specific problem is with the examples. I have run the examples and they seem to work. I have also tried dontrun and donttest, but the same error occurred. The strangest thing is that R automatically provides the result of its attempts to run the code, with the error report. But the output provided appears accurate. Everything seems to be working, except the CMD check flags it as an error and stops the checks. Please help! I am really not a computer scientist, so I am very much out of my element! The error is at the bottom! Thank you all!

Error:

base::assign(".dptime", (proc.time() - get(".ptime", pos = "CheckExEnv")), pos = "CheckExEnv") base::cat("bcor", base::get(".format_ptime", pos = 'CheckExEnv')(get(".dptime", pos = "CheckExEnv")), " ", file=base::get(".ExTimings", pos = 'CheckExEnv'), append=TRUE, sep="") Error in format(x[1L:3L], digits = 7L) : unused argument (digits = 7) Calls: -> Execution halted

Problem code (though this isn't the only one that's had issues, depending on which is tested first):

bcor=function(data,iter,burn,seed,CI,S0,nu0,mu0){

  filler=matrix(nrow=ncol(data),ncol=ncol(data))
  for (a in 1:ncol(data)){
    for (b in 1:ncol(data)){
      filler[a,b]=ifelse(a==b,cov(data,use="pairwise.complete.obs")[a,b],0)}}
  filler1=matrix(nrow=ncol(data),ncol=ncol(data))
  for (a in 1:ncol(data)){
    for (b in 1:ncol(data)){
      filler1[a,b]=ifelse(missing(S0),filler[a,b],S0[a,b])}}
  for (a in 1:ncol(data)){
    for (b in 1:ncol(data)){
      filler1[a,b]=ifelse(missing(S0),filler[a,b],S0[a,b])}}
  S0=filler1
  L0=S0
  nu0=ifelse(missing(nu0),ncol(data)*(ncol(data)+1)/2-1,nu0)
  filler2=vector(length=ncol(data))
  for (a in 1:ncol(data)){
    filler2[a]=ifelse(missing(mu0),rep(0,ncol(data)),mu0)
  }
  mu0=filler2
  n=nrow(data)
  ybar=colMeans(data,na.rm=T)
  Sigma=cov(data,use="pairwise.complete.obs")
  seed=ifelse(missing(seed),999,seed)
  iter=ifelse(missing(iter),5000,iter)
  burn=ifelse(missing(burn),iter/2,burn)
  THETA=SIGMA=NULL

  set.seed(seed)
  pct=rep(0,iter+1)
  print(noquote("Sampling, this may take a minute"))
  for(s in 1:iter)
  {
    ###Update theta
    Ln=solve(solve(L0) + n*solve(Sigma))
    mun=Ln%*%(solve(L0)%*%mu0+n*solve(Sigma)%*%ybar)
    theta=mvrnorm(1,mun,Ln)
    ###Update sigma
    Sn=S0 + (t(data)-c(theta))%*%t( t(data)-c(theta))
    Sigma=solve(rwish(nu0+n, solve(Sn)))

    ###Save results
    THETA=rbind(THETA,theta)
    SIGMA=rbind(SIGMA,c(Sigma))
    pct[s+1]=(round(s/iter*10,1))*10
    if(pct[s+1]!=pct[s]){print(noquote(paste(pct[s+1],"%")))}
  }
  CI=ifelse(missing(CI),0.95,CI)
  CI=ifelse(CI>1,CI/100,CI)
  COR=NULL
  mat=matrix(nrow=ncol(data),ncol=ncol(data))
  cor=matrix(nrow=ncol(data),ncol=ncol(data),0)
  print(noquote("Calculating correlations, this may take a minute"))
  pct=rep(0,nrow(SIGMA)-burn+1)
  for (s in burn:nrow(SIGMA)){
    mat=matrix(SIGMA[s,],nrow=ncol(data),ncol=ncol(data))
    for (a in 1:ncol(data)){
      for (b in 1:ncol(data)){
        cor[a,b]=mat[a,b]/sqrt(mat[a,a]*mat[b,b])
        COR=rbind(COR,c(cor))
      }
    }
    num=(s-burn+1)
    denom=(nrow(SIGMA)-burn)
    pct[s-burn+2]=round((num/denom)*10,1)*10
    if(pct[s-burn+2]!=pct[s-burn+1]){print(noquote(paste(pct[s-burn+2],"%")))}

  }
  COR_M=NULL
  COR_SD=NULL
  COR_LL=NULL
  COR_UL=NULL
  for (a in 1:ncol(COR)){
    COR_M[a]=quantile(probs=c(0.5),COR[,a])
    COR_SD=sd(COR[1:nrow(COR),a])
    COR_LL[a]=emp.hpd(COR[,a],conf=CI)[1]
    COR_UL[a]=emp.hpd(COR[,a],conf=CI)[2]

  }

  star_ll=ifelse(COR_LL<0,1,0)
  star_ul=ifelse(COR_UL<0,1,0)
  star=ifelse(star_ll+star_ul==1," ","*")
  COR_M1=paste(round(COR_M,2),star)
  COR1=matrix(COR_M1,nrow=ncol(data),ncol=ncol(data))
  table=data.frame(COR1)
  colnames(table)=c(colnames(data))
  rownames(table)=c(colnames(data))
  diag(table)="1 "
  Out=list()
  Out$MU=THETA
  Out$SIGMA=SIGMA
  Out$M=matrix(COR_M,nrow=ncol(data),ncol=ncol(data))
  Out$SD=matrix(COR_SD,nrow=ncol(data),ncol=ncol(data))
  Out$LL=matrix(COR_LL,nrow=ncol(data),ncol=ncol(data))
  Out$UL=matrix(COR_UL,nrow=ncol(data),ncol=ncol(data))
  Out$Table=table

  return(Out)

question from:https://stackoverflow.com/questions/65894404/r-cmd-check-errors-on-examples-examples-work

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...