[Rd] possible bug in conflicts() (PR#9760)

rmh at temple.edu rmh at temple.edu
Wed Jun 27 17:59:02 CEST 2007


# R for Windows will not send your bug report automatically.
# Please copy the bug report (after finishing it) to
# your favorite email program and send it to
#
#       r-bugs at r-project.org
#
######################################################

Dare I say the word: bug.  It looks to me like a bug in conficts().
The use of seq_along in this line in base::conflicts
+     for (i in seq_along(where)) z[[i]] <- objects(pos = where[i])
is not appropriate.  It has the effect of ignoring the names of the
attached objects.

The proposed repair works as I wish.

> options(chmhelp = FALSE)
> if(!exists("baseenv", mode="function")) baseenv <- function() NULL
> options(STERM='iESS', editor='gnuclient.exe')
> search()
 [1] ".GlobalEnv"        "package:stats"     "package:graphics" 
 [4] "package:grDevices" "package:utils"     "package:datasets" 
 [7] "package:rcom"      "package:methods"   "Autoloads"        
[10] "package:base"     
> ls(all=TRUE)
character(0)
> conflicts(detail=TRUE)
$`package:methods`
[1] "body<-"

$`package:base`
[1] "body<-"

> conflicts(where=search()[c(8,10)], detail=TRUE)  ## this is effectively using search()[1:2]
list()
> conflicts <-
+ function (where = search(), detail = FALSE) 
+ {
+     if (length(where) < 1) 
+         stop("argument 'where' of length 0")
+     z <- vector(length(where), mode = "list")
+     names(z) <- where
+     for (i in where) z[[i]] <- objects(pos = i)  ## rmh
+     all <- unlist(z, use.names = FALSE)
+     dups <- duplicated(all)
+     dups <- all[dups]
+     if (detail) {
+         for (i in where) z[[i]] <- z[[i]][match(dups, z[[i]], 
+             0)]
+         z[sapply(z, function(x) length(x) == 0)] <- NULL
+         z
+     }
+     else dups
+ }
> 
> conflicts(where=search()[c(8,10)], detail=TRUE)  ## now it honors c(8,10)
$`package:methods`
[1] "body<-"

$`package:base`
[1] "body<-"

> conflicts(detail=T)
$.GlobalEnv
[1] "conflicts"

$`package:methods`
[1] "body<-"

$`package:base`
[1] "body<-"    "conflicts"

> bug.report()
bug.report()
The unsent bug report can be found in file c:/tmp/R.bug.report 
> 

--please do not edit the information below--

Version:
 platform = i386-pc-mingw32
 arch = i386
 os = mingw32
 system = i386, mingw32
 status = 
 major = 2
 minor = 5.0
 year = 2007
 month = 04
 day = 23
 svn rev = 41293
 language = R
 version.string = R version 2.5.0 (2007-04-23)

Windows XP Home (build 2600) Service Pack 2.0

Locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United 
States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

Search Path:
 .GlobalEnv, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, 
package:rcom, package:methods, Autoloads, package:base



More information about the R-devel mailing list