Re: [Rd] load.R patch suggestion

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Wed, 28 Sep 2011 12:18:12 +0200

>>>>> Ben Bolker <bbolker_at_gmail.com>
>>>>> on Thu, 15 Sep 2011 11:03:26 +0200 writes:

> Inspired by

> http://stackoverflow.com/questions/7487778/could-you-tell-me-what-this-error-means

> I wrote the following very small (one-line) patch which
> returns an *informative* error message when R tries to
> load a zero-byte file rather than

> Error in if (!grepl("RD[AX]2\n", magic)) { : argument is
> of length zero

> I would guess that error messages with the word "magic"
> in them would be disturbing to new users, who are probably
> worried already that R is magic ...

:-) indeed...

While it would not be a good idea to program around such error messages in general, as each extra if(...) is executed everytime the function is called, i.e. has a (albeit *very small*) penalty for every correct call just for the sake of that message in the erronous call case,
I do agree that it is worth here and so have added it (for R-devel only).

Thank you, Ben.

> Ben Bolker

> ----------------------------------------------------------------------
> Index: load.R
> ===================================================================
> --- load.R	(revision 56743)
> +++ load.R	(working copy)
> @@ -25,6 +25,7 @@
>          ## Since the connection is not open this opens it in binary mode
>          ## and closes it again.
>          magic <- readChar(con, 5L, useBytes = TRUE)
> +        if (length(magic)==0) stop("empty (zero-byte) file")
>          if (!grepl("RD[AX]2\n", magic)) {
>              ## a check while we still know the call to load()
>              if(grepl("RD[ABX][12]\r", magic))
>
> ----------------------------------------------------------------------

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 28 Sep 2011 - 11:03:20 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 28 Sep 2011 - 12:30:35 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive