R-alpha: Bugs: (1) source(.): bug in 'eval' ?; (2) cat("abc", NULL, "def\n")

Martin Maechler (maechler@stat.math.ethz.ch)
Mon, 25 Mar 1996 16:10:53 +0100


Date: Mon, 25 Mar 1996 16:10:53 +0100
Message-Id: <199603251510.QAA09603@ingrid.ethz.ch>
From: Martin Maechler <maechler@stat.math.ethz.ch>
To: R-testers@stat.math.ethz.ch
Subject: R-alpha: Bugs: (1) source(.): bug in 'eval' ?;   (2)  cat("abc", NULL, "def\n")

Two bugs / problems,  no fix:

1) The problem that Paul Gilbert reported, I can reproduce, both on SunOS
  and Solaris. The bug was not in 0.2.

 The bug appears even for a very short file which I source.

 It is happening when the statement

	eval(i, envir)

 is executed

 Here is an "debugging" version of the function source :

    source <- function (file, local = F)
    {
      if (local)
	envir <- sys.parent()
	else if (!local)
	  envir <- globalEnv
    cat("'envir' chosen:");print(envir)
      exprs <- parse(n = -1, file = file)
    cat("--> parsed", length(exprs), "expressions; now eval(.)ing them:\n")

      if (length(exprs) == 0)
	return(invisible())
      for (i in exprs) {
    cat(" before '", deparse(i), "':\n", sep='')
	yy <- eval(i, envir)
    cat(" .. after", deparse(i), ":\n")
      }
      invisible(yy)
    }

and here is an example:

  > source('/soft/sunos5_1/R-alpha-0.3/demos/graphics-1.S')
  'envir' chosen:<environment: R_GlobalEnv>
  --> parsed 7 expressions; now eval(.)ing them:
   before 'x <- rnorm(100)':
  Error: Object "i" not found



2) There is a bug, in cat :

 Example (you can imagine that this situations arises in many places,
	 at least it does in my code ...)

   cat("Result:", if(FALSE) "-- some case", "\n")
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   Error in cat(list(...), file, sep, fill, labels, append) : argument 2 has invalid type

 -----
 in July 1995,  I had e-mailed the following concerning this bug

MM> >>>>> "Ross" == Ross Ihaka <ihaka@stat.auckland.ac.nz> writes:
MM> 
MM>     Ross> 1) The "cat" problem.  Robert suggests two alternatives.
MM> 
MM>     Ross> 	1) we do what S does - the NULL and its trailing separator
MM>     Ross> are omitted.  Thus cat(1,2,NULL,"\n",sep=":") would produce 1:2:
MM> 
MM>     Ross> 	2) The NULL is omitted, but the trailing separator remains.
MM>     Ross> cat(1,2,NULL,"\n",sep=":") would produce 1:2::
MM> 
MM>     Ross> What do you think the right solution is?
MM> 
MM> I'd always go for compatibility first (excuse, this may sound stupid...).
MM> In our situation, however, I think that both '1)' and '2)' make sense.
MM> It really depends where the NULL comes from.
MM> 	[are we talking about NULL alone or also  'real(0)'  ?]
MM> 
MM> Couldn't you allow an extra argument 'keep.sep = false'
MM> which does 1) [by default keep.sep is false and 'sep' is not kept for NULL]
MM> and does   2) when it is 'true', it "keeps" "sep".

And I still like my answer:

- by default, remain compatible with S
- allow the behavior '2)'  where the 'sep' is kept

Martin

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- To (un)subscribe, send
subscribe	or	unsubscribe
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-