[R] subscript out of bounds

Fred Jean Frederic.Jean at univ-brest.fr
Tue Jul 2 13:31:28 CEST 2002


Hello

As I'm beginning to write functions, I decided to have my personnal R library
named MyStuff located in /home/fred/R.Lib/MyStuff/

The library file itself is at /home/fred/R.Lib/MyStuff/R/MyStuff

evrything seems ok since 
> library()
            gives : 

Packages in library `/usr/lib/R/library':

KernSmooth              Functions for kernel smoothing for Wand &
                        Jones (1995)
MASS                    Main Library of Venables and Ripley's MASS
Simple
base                    The R base package
...

Packages in library `~/R.Lib/':

MyStuff                 Mes fonctions 'made in maison'
  but :
>library(MyStuff)
Error: subscript out of bounds

I don't understand where I'm wrong because the functions in MyStuff
individually work well when I just paste them from my editor.

Thanks for any help
Fred

Linux debian potato
R     1.5.0

here below, the file MyStuff
-----------------------------
"adjresid" <- function(tab) {
   # calcul des residus normes sur un tableau de contingence
   # adjusted Pearson residuals
   # Brett Presnell <presnell at stat.ufl.edu>
   #
   tot <- sum(tab)
   rp <- apply(tab, 1, sum) / tot
   cp <- apply(tab, 2, sum) / tot
   mu <- tot * ( rp %o% cp )
   norm(tab - mu) / sqrt( mu * ( (1 - rp) %o% (1 - cp) ) )
}
"twoWay" <- function(x=NA, y=NA, userDefined=NA ) {
  # adapted from Mark Myatt <mark at myatt.demon.co.uk>
  if (is.na(userDefined)){
  result <- chisq.test(table(x,y))
  }
  else{
  result <- chisq.test(userDefined)
  }
  #
  print(result)
  obs <- result$observed
  exp <- result$expected
  chi.table <- ((obs - exp)^2)/exp
  row.sum <- apply(obs,1,sum)
  col.sum <- apply(obs,2,sum)
  N <- sum(obs)
  #     
  fullArray <- cbind(obs,row.sum) 
  fullArray <- rbind(fullArray,c(col.sum,N))
  rownames(fullArray) <- c(rownames(obs), "Total") 
  colnames(fullArray) <- c(colnames(obs), "Total")
  #
  return(list(Complet=fullArray,Expected=exp,Chi=chi.table))
}

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list