[R] bug in installed.packages {was "Problem... mgcv PACKAGES file.."}

Martin Maechler maechler at stat.math.ethz.ch
Thu Jun 3 09:36:36 CEST 2004


Hi Robert,

>>>>> "Robert" == Robert King <robert.king at newcastle.edu.au>
>>>>>     on Thu, 3 Jun 2004 16:58:16 +1000 (EST) writes:

    Robert> Hello All, I'm getting this error (Version: 1.9.0-1
    Robert> on a debian system)

    >> update.packages("mgcv")
    Robert> trying URL
    Robert> `ftp://mirror.aarnet.edu.au/pub/cran/src/contrib/PACKAGES'
    Robert> ftp data connection made, file length 169516 bytes
    Robert> opened URL
    Robert> .......... .......... .......... .......... ..........
    Robert> .......... .......... .......... .......... ..........
    Robert> .......... .......... .......... .......... ..........
    Robert> .......... .....  downloaded 165Kb

    Robert> Error in "colnames<-"(`*tmp*`, value = c("Package",
    Robert> "LibPath", pkgFlds)) : attempt to set colnames on
    Robert> object with less than two dimensions

I can confirm the problem (with R 1.9.1 alpha of a few days ago)
It's not related to "mgcv" at all.

For didactical purposes I show here how to find out more 
(i.e. how to start learning to debug):

> update.packages("sfsmisc")
trying URL `http://cran.ch.r-project.org/src/contrib/PACKAGES'
Content type `text/plain; charset=ISO-8859-1' length 169516 bytes
opened URL
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .....
downloaded 165Kb

Error in "colnames<-"(`*tmp*`, value = c("Package", "LibPath", pkgFlds)) : 
	attempt to set colnames on object with less than two dimensions

  [same bug --- now one crucial thing to learn : ]
		    --------------------------
> traceback()
5: stop("attempt to set colnames on object with less than two dimensions")
4: "colnames<-"(`*tmp*`, value = c("Package", "LibPath", pkgFlds))
3: installed.packages(lib.loc = lib.loc)
2: old.packages(lib.loc = lib.loc, contriburl = contriburl, method = method, 
       available = available)
1: update.packages("sfsmisc")

  [ok, it's inside  installed.packages() that the problem occurs;
   hence let's look inside there : ]

> debug(installed.packages)
> update.packages("sfsmisc")
trying URL `http://cran.ch.r-project.org/src/contrib/PACKAGES'
Content type `text/plain; charset=ISO-8859-1' length 169516 bytes
opened URL
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .....
downloaded 165Kb

debugging in: installed.packages(lib.loc = lib.loc)
debug: {
    if (is.null(lib.loc)) 
        lib.loc <- .libPaths()
    pkgFlds <- c("Version", "Priority", "Bundle", "Depends")
    if (!is.null(priority)) {
        if (!is.character(priority)) 
            stop("`priority' must be character or NULL")
        if (any(b <- priority %in% "high")) 
            priority <- c(priority[!b], "recommended", "base")
    }
    retval <- character()
    for (lib in lib.loc) {
        pkgs <- .packages(all.available = TRUE, lib.loc = lib)
        for (p in pkgs) {
            desc <- unlist(packageDescription(p, lib = lib, fields = pkgFlds))
            if (!is.null(priority)) 
                if (is.na(pmatch(desc["Priority"], priority))) 
                  next
            retval <- rbind(retval, c(p, lib, desc))
        }
    }
    if (!is.null(retval)) 
        colnames(retval) <- c("Package", "LibPath", pkgFlds)
    retval
}
Browse[1]> 
debug: if (is.null(lib.loc)) lib.loc <- .libPaths()
Browse[1]> 
debug: pkgFlds <- c("Version", "Priority", "Bundle", "Depends")
Browse[1]> 
debug: if (!is.null(priority)) {
    if (!is.character(priority)) 
        stop("`priority' must be character or NULL")
    if (any(b <- priority %in% "high")) 
        priority <- c(priority[!b], "recommended", "base")
}
Browse[1]> 
debug: retval <- character()
Browse[1]> 
debug: for (lib in lib.loc) {
    pkgs <- .packages(all.available = TRUE, lib.loc = lib)
    for (p in pkgs) {
        desc <- unlist(packageDescription(p, lib = lib, fields = pkgFlds))
        if (!is.null(priority)) 
            if (is.na(pmatch(desc["Priority"], priority))) 
                next
        retval <- rbind(retval, c(p, lib, desc))
    }
}
Browse[1]> 
debug: lib
Browse[1]> 
debug: pkgs <- .packages(all.available = TRUE, lib.loc = lib)
Browse[1]> 
debug: for (p in pkgs) {
    desc <- unlist(packageDescription(p, lib = lib, fields = pkgFlds))
    if (!is.null(priority)) 
        if (is.na(pmatch(desc["Priority"], priority))) 
            next
    retval <- rbind(retval, c(p, lib, desc))
}
Browse[1]> 
debug: if (!is.null(retval)) colnames(retval) <- c("Package", "LibPath", 
    pkgFlds)
Browse[1]> retval
character(0)
Browse[1]> 
Error in "colnames<-"(`*tmp*`, value = c("Package", "LibPath", pkgFlds)) : 
	attempt to set colnames on object with less than two dimensions
> 

----------------

If look at the last dozen lines the bug is "obvious"
["Good Programming rule":   
       !is.null(.) is NOT the same as length(.) > 0
]

What I don't understand is that it took so long before the
problem was seen by someone...

It also seems to me that the value of lib.loc (namely "sfsmisc")
at that moment is wrong as well - which would point to a problem
in the update.packages() function...  

Well, anyway, more details belong to R-bugs / R-devel,
not here (R-help).

Martin Maechler




More information about the R-help mailing list