Bug 15455 - readRegistry returns unnamed duplicate entry for each entry named "(Default)"
readRegistry returns unnamed duplicate entry for each entry named "(Default)"
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: Windows GUI / Window specific
R 3.0.1
x86_64/x64/amd64 (64-bit) Windows 64-bit
: P5 normal
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2013-09-14 03:19 UTC by Bill Dunlap
Modified: 2013-09-27 15:58 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bill Dunlap 2013-09-14 03:19:38 UTC
When readRegistry() returns a list with an entry named "(Default)", there is always (I think) a duplicate but unnamed entry immediately after it.  E.g.

> readRegistry("SOFTWARE\\ActiveState\\ActivePerl\\1402")
$`(Default)`
[1] "C:\\Perl64\\"

[[2]]
[1] "C:\\Perl64\\"

$Help
[1] "<subkey>"

> readRegistry("SOFTWARE\\Artifex\\GPL Ghostscript\\9.05")
$`(Default)`
[1] "C:\\Program Files\\gs\\gs9.05"

[[2]]
[1] "C:\\Program Files\\gs\\gs9.05"

Here is a function to tally the number of (Default) entries followed by an unnamed identical entry vs. (Default) entries not followed by an unnamed identical entry.  Using the print=TRUE argument will have it print the names on the suspicious entries.
scanReg2 <- function(p, print = FALSE) {
    nDefaultEqualsNext <- 0
    nDefaultNotEqualToNext <- 0
    scannerPrint <- function(p, stem="") {
        if (is.list(p)) {
            nms <- names(p)
            if (!is.null(nms)) {
                nms[nms == ""] <- paste0("[[", seq_along(nms), "]]")[nms == ""]
            }
            if (is.element("(Default)", nms)) {
                cat(stem, ": {", paste(nms, sep=", "), "}\n", sep="") ;
            }
            for(i in seq_along(p)) {
                Recall(p[[i]], stem=paste(sep="\\", stem, nms[i]))
            }
        }
        invisible()
    }
    if (print) {
        scannerPrint(p)
    }
    scannerTally <- function(p) {
        if (is.list(p)) {
            nms <- names(p)
            if ( (i <- match("(Default)", nms, 0)) > 0 ) {
                if (i < length(nms) && nms[i+1]=="" && identical(p[[i]], p[[i+1]])) {
                    nDefaultEqualsNext <<- nDefaultEqualsNext + 1
                } else {
                    nDefaultNotEqualToNext <<- nDefaultNotEqualToNext + 1
                }
            }
            for(i in seq_along(p)) {
                Recall(p[[i]])
            }
        }
    }
    scannerTally(p)
    c(nDefaultEqualsNext=nDefaultEqualsNext, nDefaultNotEqualToNext=nDefaultNotEqualToNext)
}

I scanned a big chuck of my registry with this and found that all 10^5 (Default) entries were followed by identical unnamed entries:

> p <- readRegistry("SOFTWARE", maxdepth=5)
There were 31 warnings (use warnings() to see them)
> scanReg2(p)
    nDefaultEqualsNext nDefaultNotEqualToNext 
                104732                      0 
 
I compared the readRegistry output for SOFTWARE\ActiveState to the output of the Windows 'reg query /s' command and it looks the unnamed entry following the (Default) should not be there.

> shell("reg query HKLM\\SOFTWARE\\ActiveState /s")

HKEY_LOCAL_MACHINE\SOFTWARE\ActiveState\ActivePerl
    CurrentVersion    REG_SZ    1402

HKEY_LOCAL_MACHINE\SOFTWARE\ActiveState\ActivePerl\1402
    (Default)    REG_SZ    C:\Perl64\

HKEY_LOCAL_MACHINE\SOFTWARE\ActiveState\ActivePerl\1402\Help
    (Default)    REG_SZ    C:\Perl64\html\index.html

HKEY_LOCAL_MACHINE\SOFTWARE\ActiveState\PerlScript

HKEY_LOCAL_MACHINE\SOFTWARE\ActiveState\PerlScript\1.0
    NoCaseCompare    REG_DWORD    0x1
    EnabledZones    REG_DWORD    0x10
    EnableEventLogMsgs    REG_DWORD    0x0

> readRegistry("SOFTWARE\\ActiveState", maxdepth=3)
$ActivePerl
$ActivePerl$CurrentVersion
[1] "1402"

$ActivePerl$`1402`
$ActivePerl$`1402`$`(Default)`
[1] "C:\\Perl64\\"

$ActivePerl$`1402`[[2]]
[1] "C:\\Perl64\\"

$ActivePerl$`1402`$Help
[1] "<subkey>"



$PerlScript
$PerlScript$`1.0`
$PerlScript$`1.0`$EnabledZones
[1] 16

$PerlScript$`1.0`$EnableEventLogMsgs
[1] 0

$PerlScript$`1.0`$NoCaseCompare
[1] 1
Comment 1 Duncan Murdoch 2013-09-27 15:58:58 UTC
Fixed in R-devel, soon in R-patched