Skip to content

another save/load problem, only(?) affecting ascii = TRUE (PR#507)

2 messages · Martin Maechler, Peter Dalgaard

#
On all current R versions, afaik:

When using  save(....., ascii = TRUE),
the resulting file is not always readable by load(.).

The following is executable R code
exhibiting two (slightly different) examples
of which I have seen even more [~/R/MISC/saveload-bug.R]:

### BUG :  save(..., ascii = TRUE)  produces load() -  unreadable files :

tstf1 <- function(n = 500)
{
    ## Purpose:
    ## -----------------------------------------------------------------------
    ## Author: Martin Maechler, Date: 29 Mar 2000, 15:40
    ## -----------------------------------------------------------------------
    n2 <- n %/% 2
    nk <- n2 * 4
    CPU <- numeric(n)
    ## -----------------------------------------------------------------------
    for(i in 1:n) { ## just a simple pseudo loop
        n <- n*nk
        CPU[i] <- i^n
    }
    CPU
}

tstf2 <- function(n = 500)
{
    ## Author: Martin Maechler, Date: 1 Apr 2000, 15:40
    n %/% 2
}

save(tstf1, file="foo1",ascii=TRUE); load(file="foo1")
## Error in load(file = "foo1") : NewReadItem: unknown type -1073749696
save(tstf2, file="foo2",ascii=TRUE); load(file="foo2")
## Error in load(file = "foo2") : NewReadItem: unknown type 92

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
maechler@stat.math.ethz.ch writes:
Squished (I think). Problem was that nonprinting characters (incl. the
Space character) were printed in octal using %o format in
OutStringAscii. That should be %.3o to ensure that exactly three octal
digits get printed. Otherwise we're in trouble every time a digit
follows a space. 

I kind of suspect that there's really no reason to escape spaces like
that, but we'd have the same problem with other unprintables.

The $ffff question is whether %.3o is guaranteed to work on all
platforms.