revbayes / revbayes.archive

GNU General Public License v3.0
68 stars 37 forks source link

Bug in vector assignment #143

Open jembrown opened 5 years ago

jembrown commented 5 years ago

Something about the way vectors and vector elements are created and/or assigned leads to a bug when reassigning a vector to a variable name. In this example, testVec[1] should be 0 at the end.

> testVec = v(0,0)
> testVec[1] += 1
> testVec
   [ 1, 0 ]
> testVec = v(0,0)
> testVec
   [ 0, 0 ]
> testVec[1]
   1
jembrown commented 5 years ago

I'm following up on this, because I just ran into it again. In this case, I was trying to sort a vector, reassign the sorted vector to the original variable name, and access individual elements in the sorted vector. This works properly when the vector is defined all at once. But it fails when the vector is created by assigning to individual indices.

> myVec <- [1.2,6.7,4.5]
> myVec
   [ 1.200, 6.700, 4.500 ]
> myVec <- sort(myVec)
> myVec
   [ 1.200, 4.500, 6.700 ]
> myVec[2]
   4.5
> myVec[3]
   6.7
> myVecTwo[1] <- 1.2
> myVecTwo[2] <- 6.7
> myVecTwo[3] <- 4.5
> myVecTwo
   [ 1.200, 6.700, 4.500 ]
> myVecTwo <- sort(myVecTwo)
> myVecTwo
   [ 1.200, 4.500, 6.700 ]
> myVecTwo[2]
   6.7