[R] bwplot does something weird with Hmisc library attached

Martin Maechler maechler at stat.math.ethz.ch
Thu Jul 17 10:24:51 CEST 2003


>>>>> "Petr" == Petr Pikal <petr.pikal at precheza.cz>
>>>>>     on Wed, 16 Jul 2003 17:13:57 +0200 writes:

    Petr> Dear all I would like to ask you about possible bug in
    Petr> using bwplot (from lattice) together with Hmisc
    Petr> library attached. I found it in my actual data, but
    Petr> here is a toy example. It appears only when some
    Petr> levels are missing.

    Petr> library(lattice) 
    Petr> library(Hmisc)

    ..............

    Petr> The levels for factor f1 are in the OOOPS case
    Petr> reversed, maybe it has something to do with factor
    Petr> redefinition as stated when attaching Hmisc library.

exactly.
Because of this:

  >> > library(Hmisc)
  >> Hmisc library by Frank E Harrell Jr
  >> 
  >> Type library(help='Hmisc'), ?Overview, or ?Hmisc.Overview')
  >> to see overall documentation.
  >> 
  >> Hmisc redefines [.factor to drop unused levels of factor variables
  >> when subscripting. To prevent this behaviour, issue the command
  >> options(drop.unused.levels=F).
  >> 
  >> Attaching package 'Hmisc':
  >> 
  >> 
  >> 	The following object(s) are masked from package:survival :
  >> 
  >> 	 as.data.frame.Surv untangle.specials 
  >> 
  >> 
  >> 	The following object(s) are masked from package:stepfun :
  >> 
  >> 	 ecdf 
  >> 
  >> 
  >> 	The following object(s) are masked from package:base :
  >> 
  >> 	 [.factor %in% interaction [.terms 

where only the last line is the real crucial problem,
(and "%in%" is I think identical to R base's definition)
using Hmisc unfortunately can break anything that internally
uses  "[.factor"(), interaction(), or  "[.terms"()
where the first is your problem.

If you look closer at the text above, you see

  >>> To prevent this behaviour, issue the command 
  >>    options(drop.unused.levels=F).

and that's your solution: Issue

    options(drop.unused.levels = FALSE)

    ## "FALSE", not "F", since "F" can be anything: it's valid
                variable name which initially is set to FALSE!

I would set this option everytime when using Hmisc, because
otherwise `anything' else can be broken by the changed factor
subsetting behavior.

---

Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><




More information about the R-help mailing list