[Rd] Maybe some bug on sapply and cbind (PR#5628)

Remy.Drouilhet at upmf-grenoble.fr Remy.Drouilhet at upmf-grenoble.fr
Tue Dec 9 11:30:36 MET 2003


Full_Name: Drouilhet Rémy
Version: 1.8.1
OS: Linux
Submission from: (NULL) (195.221.43.136)


Hi!!!

Is there some mistake?
This is some part of one of my R programs. I created this function to show you
the trouble!!!

bugTest<-function() {
  paramnames <- c("mean","sd")
  param <- list(expression(1),expression(2))
  paramtmp <- list(mean=0,sd=1)
  if(length(param)) {
      sapply(1:length(param),function(i)
paramtmp[[paramnames[i]]]<<-param[[i]])
  }
  paramtmp
}

If you run :

> bugTest()
$mean
expression(1)

$sd
expression(2)

Everything seems Ok!!! But, now, continue by running :
> cbind(1,rep(2,1))
Segmentation fault

In fact, every cbind, rbind applying vectors seem to fail.

Now, change in the bugTest the sapply by some for instance:

bugTest2<-function() {
  paramnames <- c("mean","sd")
  param <- list(expression(1),expression(2))
  paramtmp <- list(mean=0,sd=1)
  if(length(param)) {
      for( i in 1:length(param)) paramtmp[[paramnames[i]]]<-param[[i]]
  }
  paramtmp
}

>  bugTest2()
$mean
expression(1)

$sd
expression(2)

>  cbind(1,rep(2,1))
     [,1] [,2]
[1,]    1    2

NOW, EVERYTHING IS OK!!!

I hope this could be helpful for us!!

Bye



More information about the R-devel mailing list