[R] edit/environment bug??

Scholz, Fritz Fritz.Scholz at boeing.com
Fri May 19 02:06:37 CEST 2006


I sent the query below out to 'cran at r-project.org'
which was probably not appropriate.

I seem to have run into some weird behavior concerning the latest
Windows version 2.3.0 of R.
It does not happen in 2.2.1. 
I have reduced it to a very simple exersise and I attach the workspace
after things are messed up.
That workspace is no longer readable by R 2.2.1.
 <<.RData>> 
==============================================
If this workspace gets filtered out of you e-mail, it contains two
objects
dat=rnorm(100)
and the function
test.fun = function (x = dat) 
{
    par(mfrow = c(2, 1))
    for (i in 1:2) {
        hist(x)
    }
}

To get the messed up version of fun, follow the steps below.
===============================================

When you spool test.fun without () in R 2.3.0 with the messed up version
you get

> ls()
[1] "dat"      "test.fun"
> test.fun
function (x = dat) 
{
    par(mfrow = c(2, 1))
    for (i in 1:2) {
        hist(x)
    }
}
<environment: base>

and test.fun() no longer runs as it should.

The way I got to this version of test.fun was to edit it via
fix(test.fun)
I introduced an error (leaving off the ) in hist)

function (x = dat) 
{
    par(mfrow = c(2, 1))
    for (i in 1:2) {
        hist(x
    }
}

and after saving this messed up function
I got Error in edit(name, file, title, editor) : 
        an error occurred on line 6
 use a command like
 x <- edit()
 to recover

I then did
x=edit()
fixed the error, saved again and did
test.fun=x.

After that this weird <environment: base>
showed up when before it was not there.

I have no experience with environments and don't know
whether this is normal. It certainly does not happen this
way when I do it in R 2.2.1.
The same problem was verified in Unix R 2.3.

I hope someone can enlighten me. I tried to look at the various 
FAQ but could not make a link.




Fritz Scholz
Applied Statistics Group
Boeing Phantom Works
fritz.scholz at boeing.com
425-865-3623




More information about the R-help mailing list