From plindsey@luc.ac.be  Thu Jul 31 08:34:02 1997
From: plindsey@luc.ac.be (Patrick Lindsey)
Date: Thu, 31 Jul 1997 09:34:02 +0200 (MET DST)
Subject: R-alpha: More problems with R0.50.a1
Message-ID: <9707310734.AA26662@alpha.luc.ac.be>

More problems...

1) when -lf2c is used for linking as in the standard Makefile in
src/main, it does not include the library as shown by ldd on my
slackware linux 2.0.29 but does on RedHat linux 2.0.27. But with
slackware adding the -L/usr/lib just before -lf2c does include it. On
the other hand readline in the same directory is included both times.
(We need the f2c library for complex numbers in Richard Jones' carma
for kalman filtering which we are dynamically loading.)

2) matrix(2,nrow=3,ncol=3)[!is.na(matrix(2,nrow=3,ncol=3))]
gives a vector of nine 2's
if the matrix has row and column names, the vector has the 3 column
names completed with six NA names.

3) Robert's example on 'Environment strangeness' has 2 errors:
	- missing bracket on the second last line of his g function.
	- should not try to print before b has been retrieved from the
	  appropriate environment (on same line as above).

4) why does the following function yield errors with R scoping rules?
> p <- function () {
	b <- 123
	s()
}
> s <- function () {
	print(b)
}
> p()
Error: Object "b" not found.

5) getting the call line and saving it as an attribute:
This works:
> f <- function () {
	x <- match.call()
	print(x)
}
This recurses in an infinite loop, recalling the 'f' function each
time the "attr" line is stored in the "call" attribute of x.
> f <- function () {
	x <- 2
	print(x)
	attr(x,"call") <- match.call()
	print(attributes(x))
}

6) The following gives a error. How can this be solved?
> "[<-.newtype" <- function(...) {
	NextMethod("[<-")
}
> f <- function () {
	idx <- 2
	tmp <- matrix(3,ncol=4,nrow=4)
	class(tmp) <- "newtype"
	tmp[idx,] <- matrix(1,ncol=4,nrow=4)[2,]
}
> f()
Error: Object "idx" not found.

This did not work in R0.49 either, but does work in S..
(In R the name of the variable "idx" is passed to "[<-.newtype" in the
row and col local variable as in S it is the contents of "idx" which
are passed through.)
I had solved this for R0.49 by adding the line:
	idx <- eval(idx,sys.frame(sys.parent()))
But this does not work any more in R0.50.a1...
So I modified the line to:
        idx <- eval(expression(idx),sys.frame(sys.parent()))
but this did not change anything.
It looks as if the environments were not always retrieved properly and
that R scoping rules are not always followed. I thought that R would
be able to find any variable defined in a previous environment so that
they did not have to be passed from function to function as in S.

Patrick.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


R-alpha: More problems with R0.50.a1
Patrick Lindsey