R 0.65.x bug : attach()/eval() {was "lib.source() within library()"} (PR#264)

maechler@stat.math.ethz.ch maechler@stat.math.ethz.ch
Thu, 2 Sep 1999 12:23:53 +0200 (MET DST)


In 0.65.0  lib.source() within library()  works differently
and fails to correctly "load" a library when it wants to change an object
that it has defined previously:

Below is a very short shar file that produces a "minimal" example [no
attachment, just appended].
To reproduce  {read on, before doing it!}  do

   sh < libBug.shar <<<<< the file name you gave
   R INSTALL libBug

   echo 'library(libBug)' | R --vanilla --quiet

which gives

    Error: attempt to set an attribute on NULL
    Execution halted

----

The only R code in the whole library is in  libBug/R/only.R

    bla <- pi
    names(bla) <- "N"

However, with help of debug(library) 
and *inside* library  debug(lib.source)

I can now reproduce the problem  without needing library() directly:

    env   <- attach(NULL, name = "libBug")
    exprs <- expression(bla <- pi, names(bla) <- "N")
    for (i in exprs) yy <- eval(i, env)

    ##-> Error: attempt to set an attribute on NULL

and replacing the last line by

    for (i in exprs){ yy <- eval(i,env);print(ls(env=env))
		      cat("bla:",get("bla",env=env),"\n") }
gives

    [1] "*tmp*" "bla"  
    bla: 3.14159265358979 
    Error: attempt to set an attribute on NULL

-----

#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1999-09-02 12:00 MET DST by <maechler@sophie>.
# Source directory was `/users/u1/staff/maechler/R'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
# This format requires very little intelligence at unshar time.
# "if test", "echo", "mkdir", and "sed" may be needed.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#     28 -rw-r--r-- libBug/R/only.R
#     47 -rw-r--r-- libBug/TITLE
#
echo=echo
if mkdir _sh21127; then
  $echo 'x -' 'creating lock directory'
else
  $echo 'failed to create lock directory'
  exit 1
fi
# ============= libBug/R/only.R ==============
if test ! -d 'libBug'; then
  $echo 'x -' 'creating directory' 'libBug'
  mkdir 'libBug'
fi
if test ! -d 'libBug/R'; then
  $echo 'x -' 'creating directory' 'libBug/R'
  mkdir 'libBug/R'
fi
if test -f 'libBug/R/only.R' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'libBug/R/only.R' '(file already exists)'
else
  $echo 'x -' extracting 'libBug/R/only.R' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'libBug/R/only.R' &&
Xbla <- pi
Xnames(bla) <- "N"
SHAR_EOF
  : || $echo 'restore of' 'libBug/R/only.R' 'failed'
fi
# ============= libBug/TITLE ==============
if test -f 'libBug/TITLE' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'libBug/TITLE' '(file already exists)'
else
  $echo 'x -' extracting 'libBug/TITLE' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'libBug/TITLE' &&
XlibBug	Simple Package to show lib.source() bug
SHAR_EOF
  : || $echo 'restore of' 'libBug/TITLE' 'failed'
fi
rm -fr _sh21127
exit 0

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._