Skip to content

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

1 message · Remy.Drouilhet@upmf-grenoble.fr

#
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 :
$mean
expression(1)

$sd
expression(2)

Everything seems Ok!!! But, now, continue by running :
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
}
$mean
expression(1)

$sd
expression(2)
[,1] [,2]
[1,]    1    2

NOW, EVERYTHING IS OK!!!

I hope this could be helpful for us!!

Bye