[Rd] Bug in args with no defaults (PR#747)

dmurdoch@pair.com dmurdoch@pair.com
Sun, 26 Nov 2000 21:12:13 +0100 (MET)

This turned up in the same context as #743, i.e. writing data.restore.

Two bugs, I think:

The way arguments with no defaults are stored appears to be as a
zero-length name:

 > test <- function(x) 1
 > as.list(test)$x

 > mode(as.list(test)$x)
 [1] "name"
 > as.character(as.list(test)$x)
 [1] ""

However, I'm not allowed to create one of those:

 > as.name("")
 Error in as.name("") : attempt to use zero-length variable name

If I'm sneaky, I can create one, but I can't do anything with it:

 > badvar <- as.list(test)$x
 > badvar
 Error: Argument "badvar" is missing, with no default
 > junk <- badvar
 Error: Argument "badvar" is missing, with no default
 > junk
 Error: Object "junk" not found

For now, the workaround I'm using when building up functions like
"test" above is to create them as

 function(x = stop("argument x is missing")) 1

but this is ugly.

Duncan Murdoch

 platform = Windows
 arch = x86
 os = Win32
 system = x86, Win32
 status = 
 major = 1
 minor = 1.1
 year = 2000
 month = August
 day = 15
 language = R

Windows 9x 4.0 (build 1111)  B

Search Path:
 .GlobalEnv, Autoloads, package:base

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