[Rd] Strange assignment bug (PR#1450)

G.Innocent@vet.gla.ac.uk G.Innocent@vet.gla.ac.uk
Wed, 10 Apr 2002 15:36:20 +0200 (MET DST)


Dear bugs @r;

The following reproduces erroneous results on my system using R-gui:

platform i386-pc-mingw32
arch     x86
os       Win32
system   x86, Win32
status
major    1
minor    4.1
year     2002
month    01
day      30
language R

#####################################################

inter.gp.effect <- 0.1

animals <- data.frame(pos = 0:2)

SI.model <- function(Animal.group) {

		group <- 1
		Animal.group$pos[group] <- Animal.group$pos[group] + 1
		effective.animals <- Animal.group$pos	# allows us to model inter-group
contact
#
			effective.animals[1:(length(Animal.group$pos)-1)] <-
				effective.animals[1:(length(Animal.group$pos)-1)] +
				inter.gp.effect*Animal.group$pos[2:length(Animal.group$pos)]
##
			effective.animals[2:length(Animal.group$pos)] <-
				effective.animals[2:length(Animal.group$pos)]  +
				inter.gp.effect*Animal.group$pos[1:(length(Animal.group$pos)-1)]
	return(Animal.group)
}

print(SI.model(animals))

####################################################

results:
> source("c:\\r work\\simulation model\\bug.R")
     pos
1 1.10
2 1.31
3 2.12

Expected results:
   pos
1    1
2    1
3    2

Notes:

1) The value for group can be anywhere on the interval 1:3, the results
differ, but are consistently incorrect.

2) If Animal.group is a vector, not a data frame the error does not occur.

3) Interestingly if SI.model is run through the debugger step by step, and
the value of Animal.group examined at the place marked in the code by a
single hash, then the correct result is obtained.  If the value of
Animal.group is examined at the place marked with a double hash, then the
following (incorrect) result is obtained:

exiting from: SI.model(animals)
  pos
1 1.1
2 1.2
3 2.0

4) Pre-defining expected.animals as either a data.frame, or
vector(model="numeric") does not alter the erroneous output

5) I would suggest that at both assignments to effective.animals, the result
is also being assigned to Animal.group$pos.  Examining the value assigned to
Animal.group at an appropriate place is forcing the interpreter to assign
into Animal.group correctly, and therefore fixing its value.

6) The above code appears to be the minimum of code required to reproduce
the results on my machine.

I have taken this problem as far as my limited debugging abilities allow.  I
am not a C or Fortran guru!

I would like to take this opportunity to thank those who have contributed to
the r project for a fine piece of software.

I hope that this bug report helps.  If I can be of further assistance then
let me know.

Thanks again

Giles

Dr. G.T. Innocent
Comparative Epidemiology and Informatics Group,
Dept. of Veterinary Clinical Studies,
Glasgow University Vet. School.
Bearsden Road, Glasgow G61 1QH
Tel. 0141 339 8855 Ext. 0531.
Fax. 0141 330 5729
e-mail G.Innocent@vet.gla.ac.uk


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._