r-gregmisc-users Mailing List for R gregmisc package (Page 10)
Brought to you by:
warnes
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
(12) |
Apr
(5) |
May
(3) |
Jun
(5) |
Jul
(2) |
Aug
(5) |
Sep
(7) |
Oct
(15) |
Nov
(34) |
Dec
(3) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(3) |
Feb
(16) |
Mar
(28) |
Apr
(5) |
May
|
Jun
(5) |
Jul
(9) |
Aug
(50) |
Sep
(29) |
Oct
(9) |
Nov
(25) |
Dec
(7) |
2008 |
Jan
(6) |
Feb
(4) |
Mar
(5) |
Apr
(8) |
May
(26) |
Jun
(11) |
Jul
|
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
(9) |
2009 |
Jan
|
Feb
(1) |
Mar
|
Apr
(2) |
May
(26) |
Jun
|
Jul
(10) |
Aug
(6) |
Sep
|
Oct
(7) |
Nov
(3) |
Dec
(2) |
2010 |
Jan
(45) |
Feb
(11) |
Mar
|
Apr
(1) |
May
(8) |
Jun
(7) |
Jul
(3) |
Aug
(1) |
Sep
|
Oct
(1) |
Nov
(9) |
Dec
(1) |
2011 |
Jan
(2) |
Feb
|
Mar
|
Apr
(3) |
May
(1) |
Jun
|
Jul
|
Aug
(14) |
Sep
(29) |
Oct
(3) |
Nov
|
Dec
(3) |
2012 |
Jan
|
Feb
|
Mar
|
Apr
(7) |
May
(6) |
Jun
(59) |
Jul
|
Aug
(8) |
Sep
(21) |
Oct
|
Nov
|
Dec
|
2013 |
Jan
(1) |
Feb
|
Mar
(10) |
Apr
|
May
(18) |
Jun
(25) |
Jul
(18) |
Aug
(1) |
Sep
(6) |
Oct
(28) |
Nov
(4) |
Dec
(13) |
2014 |
Jan
(7) |
Feb
(5) |
Mar
(4) |
Apr
(36) |
May
(3) |
Jun
(7) |
Jul
(46) |
Aug
(14) |
Sep
(12) |
Oct
(2) |
Nov
|
Dec
(12) |
2015 |
Jan
(4) |
Feb
|
Mar
|
Apr
(80) |
May
(36) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <wa...@us...> - 2014-04-05 21:08:45
|
Revision: 1801 http://sourceforge.net/p/r-gregmisc/code/1801 Author: warnes Date: 2014-04-05 21:08:41 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Apply same changes to NAToUnknown that were previously applied to unknownToNA for POSIXlt. Modified Paths: -------------- trunk/gdata/tests/unitTests/runit.unknown.R Modified: trunk/gdata/tests/unitTests/runit.unknown.R =================================================================== --- trunk/gdata/tests/unitTests/runit.unknown.R 2014-04-05 18:41:50 UTC (rev 1800) +++ trunk/gdata/tests/unitTests/runit.unknown.R 2014-04-05 21:08:41 UTC (rev 1801) @@ -478,9 +478,59 @@ ## Date-time classes checkIdentical(NAToUnknown(xDate, unknown=dateUnk), xDateUnk) - checkIdentical(NAToUnknown(xPOSIXlt, unknown=POSIXltUnk), xPOSIXltUnk) checkIdentical(NAToUnknown(xPOSIXct, unknown=POSIXctUnk), xPOSIXctUnk) + + #### + ## Per Brian Ripley on 2014-01-15: + ## + ## On platforms where POSIXlt has a gmtoff component, it does not need to be set. So + ## + ## > z$gmtoff + ## [1] 3600 NA + ## > xPOSIXltUnk$gmtoff + ## [1] 3600 3600 + ## + ## (or sometimes 0, not NA). + ## + ## So although identical() correctly reports that they differ, this + ## is allowed for optional components. + ## + ## It would also be wrong to use identical() to compare isdst + ## components: isdst = -1 means unknown. + ## + ## Replaced: + ## checkIdentical(NAToUnknown(xPOSIXlt, unknown=POSIXltUnk), xPOSIXltUnk) + ## With: + tmp_NAToUnknown <- NAToUnknown(xPOSIXlt, unknown=POSIXltUnk) + tmp_xPOSIXltUnk <- xPOSIXltUnk + ## + tmp_NAToUnknown$gmtoff <- NULL # Remove $gmtoff to avoid comparison + tmp_xPOSIXltUnk$gmtoff <- NULL + ## + isdst.unknown <- unique( + c(which(is.na(tmp_NAToUnknown$isdst) | + tmp_NAToUnknown$isdst==-1 + ) + ) + , + c(which(is.na(tmp_xPOSIXltUnk$isdst) | + tmp_xPOSIXltUnk$isdst==-1 + ) + ) + + ) + ## + checkIdentical(tmp_NAToUnknown$isdst[!isdst.unknown], + tmp_xPOSIXltUnk$isds[!isdst.unknown]) + ## + tmp_NAToUnknown$isdst <- NULL # Remove $isdst to avoid comparison + tmp_xPOSIXltUnk$isdst <- NULL # by checkIdentical + ## + checkIdentical(tmp_NAToUnknown, tmp_xPOSIXltUnk) + #### + + ## --- lists and data.frames --- ## with vector of single unknown values This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 18:41:53
|
Revision: 1800 http://sourceforge.net/p/r-gregmisc/code/1800 Author: warnes Date: 2014-04-05 18:41:50 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Update NEWS with latest changes Modified Paths: -------------- trunk/gdata/inst/NEWS Modified: trunk/gdata/inst/NEWS =================================================================== --- trunk/gdata/inst/NEWS 2014-04-05 18:38:23 UTC (rev 1799) +++ trunk/gdata/inst/NEWS 2014-04-05 18:41:50 UTC (rev 1800) @@ -12,6 +12,8 @@ - Unit tests and vignettes now follow R standard practice. +- Minor changes to clean up R CMD check warnings. + Changes in 2.13.2 (2013-06-28) ------------------------------ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 18:38:26
|
Revision: 1799 http://sourceforge.net/p/r-gregmisc/code/1799 Author: warnes Date: 2014-04-05 18:38:23 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Call stats::nobs instead of stats:::nobs.default within gdata::nobs.default. This avoids R CMD check warning. Modified Paths: -------------- trunk/gdata/R/nobs.R Modified: trunk/gdata/R/nobs.R =================================================================== --- trunk/gdata/R/nobs.R 2014-04-05 18:22:16 UTC (rev 1798) +++ trunk/gdata/R/nobs.R 2014-04-05 18:38:23 UTC (rev 1799) @@ -11,10 +11,10 @@ if(is.numeric(object) || is.logical(object)) sum( !is.na(object) ) else - stats:::nobs.default(object, ...) + stats::nobs(object, ...) } - + nobs.data.frame <- function(object, ...) sapply(object, nobs.default) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 18:22:18
|
Revision: 1798 http://sourceforge.net/p/r-gregmisc/code/1798 Author: warnes Date: 2014-04-05 18:22:16 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Don't compare optional POSIXlt field. Explicitly compare POSIXlt, with special handling of '-1' unknown value. Modified Paths: -------------- trunk/gdata/tests/unitTests/runit.unknown.R Modified: trunk/gdata/tests/unitTests/runit.unknown.R =================================================================== --- trunk/gdata/tests/unitTests/runit.unknown.R 2014-04-05 18:19:49 UTC (rev 1797) +++ trunk/gdata/tests/unitTests/runit.unknown.R 2014-04-05 18:22:16 UTC (rev 1798) @@ -331,9 +331,58 @@ ## Date-time classes checkIdentical(unknownToNA(xDateUnk, unknown=dateUnk), xDate) - checkIdentical(unknownToNA(xPOSIXltUnk, unknown=POSIXltUnk), xPOSIXlt) checkIdentical(unknownToNA(xPOSIXctUnk, unknown=POSIXctUnk), xPOSIXct) + #### + ## Per Brian Ripley on 2014-01-15: + ## + ## On platforms where POSIXlt has a gmtoff component, it does not need to be set. So + ## + ## > z$gmtoff + ## [1] 3600 NA + ## > xPOSIXltUnk$gmtoff + ## [1] 3600 3600 + ## + ## (or sometimes 0, not NA). + ## + ## So although identical() correctly reports that they differ, this + ## is allowed for optional components. + ## + ## It would also be wrong to use identical() to compare isdst + ## components: isdst = -1 means unknown. + ## + ## Replaced: + ## checkIdentical(unknownToNA(xPOSIXltUnk, unknown=POSIXltUnk), xPOSIXlt) + ## With: + tmp_unknownToNA <- unknownToNA(xPOSIXltUnk, unknown=POSIXltUnk) + tmp_xPOSIXlt <- xPOSIXlt + ## + tmp_unknownToNA$gmtoff <- NULL # Remove $gmtoff to avoid comparison + tmp_xPOSIXlt$gmtoff <- NULL + ## + isdst.unknown <- unique( + c(which(is.na(tmp_unknownToNA$isdst) | + tmp_unknownToNA$isdst==-1 + ) + ) + , + c(which(is.na(tmp_xPOSIXlt$isdst) | + tmp_xPOSIXlt$isdst==-1 + ) + ) + + ) + ## + checkIdentical(tmp_unknownToNA$isdst[!isdst.unknown], + tmp_xPOSIXlt$isds[!isdst.unknown]) + ## + tmp_unknownToNA$isdst <- NULL # Remove $isdst to avoid comparison + tmp_xPOSIXlt$isdst <- NULL # by checkIdentical + ## + checkIdentical(tmp_unknownToNA, tmp_xPOSIXlt) + #### + + ## --- lists and data.frames --- ## with vector of single unknown values This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 18:19:52
|
Revision: 1797 http://sourceforge.net/p/r-gregmisc/code/1797 Author: warnes Date: 2014-04-05 18:19:49 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Don't use gdata:::<foo> prefix to access gdata function <foo> Modified Paths: -------------- trunk/gdata/R/mapLevels.R trunk/gdata/R/unknown.R Modified: trunk/gdata/R/mapLevels.R =================================================================== --- trunk/gdata/R/mapLevels.R 2014-04-05 17:01:31 UTC (rev 1796) +++ trunk/gdata/R/mapLevels.R 2014-04-05 18:19:49 UTC (rev 1797) @@ -99,7 +99,7 @@ print.levelsMap <- function(x, ...) { - x <- gdata:::.unlistLevelsMap(x) + x <- .unlistLevelsMap(x) print(x, ...) } @@ -159,7 +159,7 @@ as.levelsMap <- function(x, check=TRUE, ...) { if(check) - gdata:::.checkLevelsMap(x, method="raw") + .checkLevelsMap(x, method="raw") class(x) <- "levelsMap" unique(x, ...) } @@ -167,7 +167,7 @@ as.listLevelsMap <- function(x, check=TRUE) { if(check) - gdata:::.checkListLevelsMap(x, method="raw") + .checkListLevelsMap(x, method="raw") class(x) <- "listLevelsMap" x } @@ -203,7 +203,7 @@ if(!is.list(x) || any(!sapply(x, FUN=is.levelsMap))) stop(sprintf("'%s' must be %s a list of %s", xLab, also, dQuote("levelsMap"))) - lapply(x, FUN=gdata:::.checkLevelsMap, method=method) + lapply(x, FUN=.checkLevelsMap, method=method) } ### }}} @@ -221,12 +221,12 @@ c.listLevelsMap <- function(..., sort=TRUE, recursive=FALSE) { x <- list(...) - lapply(x, FUN=gdata:::.checkListLevelsMap, method="class") + lapply(x, FUN=.checkListLevelsMap, method="class") x <- unlist(x, recursive=FALSE) if(!recursive) { class(x) <- "listLevelsMap" } else { - if(any(!sapply(x, FUN=gdata:::.isCharacterMap))) + if(any(!sapply(x, FUN=.isCharacterMap))) stop(sprintf("can not combine integer %s", dQuote("levelsMaps"))) if(!is.null(names(x))) names(x) <- NULL x <- unlist(x, recursive=FALSE) @@ -252,7 +252,7 @@ unique.levelsMap <- function(x, incomparables=FALSE, ...) { ## Find duplicates - y <- gdata:::.unlistLevelsMap(x, ind=TRUE) + y <- .unlistLevelsMap(x, ind=TRUE) ## Duplicates for values and names combinations test <- duplicated(cbind(y[[1]], names(y[[1]])), incomparables=incomparables, ...) @@ -296,7 +296,7 @@ if(any(!(class(x) %in% classX))) stop(sprintf("'x' must be either: %s", paste(dQuote(classX), collapse=", "))) - gdata:::.checkLevelsMap(x=value, method="class") + .checkLevelsMap(x=value, method="class") ## --- Mapping levels in x --- Modified: trunk/gdata/R/unknown.R =================================================================== --- trunk/gdata/R/unknown.R 2014-04-05 17:01:31 UTC (rev 1796) +++ trunk/gdata/R/unknown.R 2014-04-05 18:19:49 UTC (rev 1797) @@ -40,7 +40,7 @@ } isUnknown.list <- function(x, unknown=NA, ...) { - unknown <- gdata:::.unknownList(x=x, unknown=unknown) + unknown <- .unknownList(x=x, unknown=unknown) x <- mapply(FUN="isUnknown", x=x, unknown=unknown, ..., SIMPLIFY=FALSE) x } @@ -90,7 +90,7 @@ unknownToNA.list <- function(x, unknown, warning=FALSE, ...) { - unknown <- gdata:::.unknownList(x=x, unknown=unknown) + unknown <- .unknownList(x=x, unknown=unknown) x <- mapply(FUN="unknownToNA", x=x, unknown=unknown, warning=warning, SIMPLIFY=FALSE) return(x) @@ -148,7 +148,7 @@ NAToUnknown.list <- function(x, unknown, force=FALSE, call.=FALSE, ...) { - unknown <- gdata:::.unknownList(x=x, unknown=unknown) + unknown <- .unknownList(x=x, unknown=unknown) x <- mapply(FUN="NAToUnknown", x=x, unknown=unknown, force=force, call.=call., SIMPLIFY=FALSE) x This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 17:01:34
|
Revision: 1796 http://sourceforge.net/p/r-gregmisc/code/1796 Author: warnes Date: 2014-04-05 17:01:31 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Fix syntax error in DESCRIPTION file. Modified Paths: -------------- trunk/gdata/DESCRIPTION Modified: trunk/gdata/DESCRIPTION =================================================================== --- trunk/gdata/DESCRIPTION 2014-04-05 17:00:53 UTC (rev 1795) +++ trunk/gdata/DESCRIPTION 2014-04-05 17:01:31 UTC (rev 1796) @@ -12,4 +12,4 @@ Maintainer: Gregory R. Warnes <gr...@wa...> License: GPL-2 NeedsCompilation: no -Recommends: RUnit +Suggests: RUnit This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 17:00:55
|
Revision: 1795 http://sourceforge.net/p/r-gregmisc/code/1795 Author: warnes Date: 2014-04-05 17:00:53 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Package name needs to be defined outside of if test. Modified Paths: -------------- trunk/gdata/tests/runRUnitTests.R Modified: trunk/gdata/tests/runRUnitTests.R =================================================================== --- trunk/gdata/tests/runRUnitTests.R 2014-04-05 17:00:14 UTC (rev 1794) +++ trunk/gdata/tests/runRUnitTests.R 2014-04-05 17:00:53 UTC (rev 1795) @@ -36,28 +36,28 @@ ## make ## make all +PKG <- 'gdata' + if(require("RUnit", quietly=TRUE)) { - pkg <- 'gdata' - path <- normalizePath("unitTests") cat("\nRunning unit tests\n") - print(list(pkg=pkg, getwd=getwd(), pathToUnitTests=path)) + print(list(pkg=PKG, getwd=getwd(), pathToUnitTests=path)) - library(package=pkg, character.only=TRUE) + library(package=PKG, character.only=TRUE) testFileRegexp <- "^runit.+\\.[rR]$" ## Debugging echo cat("\nRunning RUnit tests\n") - print(list(pkg=pkg, + print(list(pkg=PKG, getwd=getwd(), pathToRUnitTests=path)) ## Define tests - testSuite <- defineTestSuite(name=paste(pkg, "RUnit testing"), + testSuite <- defineTestSuite(name=paste(PKG, "RUnit testing"), dirs=path, testFileRegexp=testFileRegexp ) @@ -68,7 +68,7 @@ if(file.access(path, 02) != 0) { ## cannot write to path -> use writable one - tdir <- tempfile(paste(pkg, "RUnitTests", sep="_")) + tdir <- tempfile(paste(PKG, "RUnitTests", sep="_")) dir.create(tdir) pathReport <- file.path(tdir, "report") } @@ -103,7 +103,7 @@ } else { cat("R package 'RUnit' cannot be loaded - no unit tests run\n", - "for package", pkg,"\n") + "for package", PKG,"\n") } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 17:00:18
|
Revision: 1794 http://sourceforge.net/p/r-gregmisc/code/1794 Author: warnes Date: 2014-04-05 17:00:14 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Style file needed Added Paths: ----------- trunk/gdata/vignettes/Rnews.sty Copied: trunk/gdata/vignettes/Rnews.sty (from rev 1786, trunk/gdata/inst/doc/Rnews.sty) =================================================================== --- trunk/gdata/vignettes/Rnews.sty (rev 0) +++ trunk/gdata/vignettes/Rnews.sty 2014-04-05 17:00:14 UTC (rev 1794) @@ -0,0 +1,204 @@ +%% +%% This is file `Rnews.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% Rnews.dtx (with options: `package') +%% +%% IMPORTANT NOTICE: +%% +%% For the copyright see the source file. +%% +%% Any modified versions of this file must be renamed +%% with new filenames distinct from Rnews.sty. +%% +%% For distribution of the original source see the terms +%% for copying and modification in the file Rnews.dtx. +%% +%% This generated file may be distributed as long as the +%% original source files, as listed above, are part of the +%% same distribution. (The sources need not necessarily be +%% in the same archive or directory.) +\def\fileversion{v0.3.6} +\def\filename{Rnews} +\def\filedate{2002/06/02} +\def\docdate {2001/10/31} +%% +%% Package `Rnews' to use with LaTeX2e +%% Copyright (C) 2001--2002 by the R Core Development Team +%% Please report errors to KH or FL +%% +%% -*- LaTeX -*- +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\ProvidesPackage{\filename}[\filedate\space\fileversion\space + Rnews package] +\typeout{Package: `\filename\space\fileversion \@spaces <\filedate>'} +\typeout{English documentation as of <\docdate>} +\RequirePackage{ifthen} +\newboolean{Rnews@driver} +\DeclareOption{driver}{\setboolean{Rnews@driver}{true}} +\DeclareOption*{\PackageWarning{\filename}{Unknown option + `\CurrentOption'}} +\ProcessOptions\relax +\ifthenelse{\boolean{Rnews@driver}}{}{ +\RequirePackage{multicol,graphicx,color,fancyhdr,hyperref} +\newcommand{\volume}[1]{\def\Rnews@volume{#1}} +\newcommand{\volnumber}[1]{\def\Rnews@number{#1}} +\renewcommand{\date}[1]{\def\Rnews@date{#1}} +\setcounter{secnumdepth}{-1} +\renewcommand{\author}[1]{\def\Rnews@author{#1}} +\renewcommand{\title}[1]{\def\Rnews@title{#1}} +\newcommand{\subtitle}[1]{\def\Rnews@subtitle{#1}} +\newenvironment{article}{% + \author{}\title{}\subtitle{}}{\end{multicols}} +\renewcommand{\maketitle}{ + \begin{multicols}{2}[\chapter{\Rnews@title}\refstepcounter{chapter}][3cm] + \ifx\empty\Rnews@subtitle\else\noindent\textbf{\Rnews@subtitle} + \par\nobreak\addvspace{\baselineskip}\fi + \ifx\empty\Rnews@author\else\noindent\textit{\Rnews@author} + \par\nobreak\addvspace{\baselineskip}\fi + \@afterindentfalse\@nobreaktrue\@afterheading} +\renewcommand\chapter{\secdef\Rnews@chapter\@schapter} +\providecommand{\nohyphens}{% + \hyphenpenalty=10000\exhyphenpenalty=10000\relax} +\newcommand{\Rnews@chapter}{% + \renewcommand{\@seccntformat}[1]{}% + \@startsection{chapter}{0}{0mm}{% + -2\baselineskip \@plus -\baselineskip \@minus -.2ex}{\p@}{% + \normalfont\Huge\bfseries\raggedright}} +\renewcommand*\l@chapter{\@dottedtocline{0}{0pt}{1em}} +\def\@schapter#1{\section*#1} +\renewenvironment{figure}[1][]{% + \def\@captype{figure} + \noindent + \begin{minipage}{\columnwidth}}{% + \end{minipage}\par\addvspace{\baselineskip}} +\renewcommand{\theequation}{\@arabic\c@equation} +\def\equation{% + \let\refstepcounter\H@refstepcounter + \H@equation + \def\newname{\arabic{chapter}.\theequation}% + \let\theHequation\newname% + \hyper@makecurrent{equation}% + \Hy@raisedlink{\hyper@anchorstart{\@currentHref}}% + \let\refstepcounter\new@refstepcounter}% +\def\endequation{\Hy@raisedlink{\hyper@anchorend}\H@endequation} +\renewcommand{\thefigure}{\@arabic\c@figure} +\renewcommand{\thetable}{\@arabic\c@table} +\renewcommand{\contentsname}{Contents of this issue:} +\renewcommand\tableofcontents{% + \section*{\contentsname + \@mkboth{% + \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}% + \@starttoc{toc}} +\renewcommand{\titlepage}{% + \noindent + \rule{\textwidth}{1pt}\\[-.8\baselineskip] + \rule{\textwidth}{.5pt} + \begin{center} + \includegraphics[height=2cm]{Rlogo}\hspace{7mm} + \fontsize{2cm}{2cm}\selectfont + News + \end{center} + The Newsletter of the R Project\hfill + Volume \Rnews@volume/\Rnews@number, \Rnews@date\\[-.5\baselineskip] + \rule{\textwidth}{.5pt}\\[-.8\baselineskip] + \rule{\textwidth}{1pt} + \vspace{1cm} + \fancyhf{} + \fancyhead[L]{Vol.~\Rnews@volume/\Rnews@number, \Rnews@date} + \fancyhead[R]{\thepage} + \fancyfoot[L]{R News} + \fancyfoot[R]{ISSN 1609-3631} + \thispagestyle{empty} + \begin{bottombox} + \begin{multicols}{2} + \setcounter{tocdepth}{0} + \tableofcontents + \setcounter{tocdepth}{2} + \end{multicols} + \end{bottombox}} +\setlength{\textheight}{250mm} +\setlength{\topmargin}{-10mm} +\setlength{\textwidth}{17cm} +\setlength{\oddsidemargin}{-6mm} +\setlength{\columnseprule}{.1pt} +\setlength{\columnsep}{20pt} +\RequirePackage{ae,mathpple} +\RequirePackage[T1]{fontenc} +\renewcommand{\rmdefault}{ppl} +\renewcommand{\sfdefault}{aess} +\renewcommand{\ttdefault}{aett} +\definecolor{Red}{rgb}{0.7,0,0} +\definecolor{Blue}{rgb}{0,0,0.8} +\definecolor{hellgrau}{rgb}{0.55,0.55,0.55} +\newcommand{\R}{R} +\newcommand{\address}[1]{\addvspace{\baselineskip}\noindent\emph{#1}} +\newcommand{\email}[1]{\href{mailto:#1}{\normalfont\texttt{#1}}} +\newsavebox{\Rnews@box} +\newlength{\Rnews@len} +\newenvironment{bottombox}{% + \begin{figure*}[b] + \begin{center} + \noindent + \begin{lrbox}{\Rnews@box} + \begin{minipage}{0.99\textwidth}}{% + \end{minipage} + \end{lrbox} + \addtolength{\Rnews@len}{\fboxsep} + \addtolength{\Rnews@len}{\fboxrule} + \hspace*{-\Rnews@len}\fbox{\usebox{\Rnews@box}} + \end{center} + \end{figure*}} +\RequirePackage{verbatim} +\def\boxedverbatim{% + \def\verbatim@processline{% + {\setbox0=\hbox{\the\verbatim@line}% + \hsize=\wd0 \the\verbatim@line\par}}% + \@minipagetrue + \@tempswatrue + \setbox0=\vbox + \bgroup\small\verbatim +} +\def\endboxedverbatim{% + \endverbatim + \unskip\setbox0=\lastbox + \egroup + \fbox{\box0} +} +\pagestyle{fancy} +} % \ifthenelse{\boolean{Rnews@driver}} +\newcommand\code{\bgroup\@codex} +\def\@codex#1{{\normalfont\ttfamily\hyphenchar\font=-1 #1}\egroup} +\newcommand{\kbd}[1]{{\normalfont\texttt{#1}}} +\newcommand{\key}[1]{{\normalfont\texttt{\uppercase{#1}}}} +\newcommand\samp{`\bgroup\@noligs\@sampx} +\def\@sampx#1{{\normalfont\texttt{#1}}\egroup'} +\newcommand{\var}[1]{{\normalfont\textsl{#1}}} +\let\env=\code +\newcommand{\file}[1]{{`\normalfont\textsf{#1}'}} +\let\command=\code +\let\option=\samp +\newcommand{\dfn}[1]{{\normalfont\textsl{#1}}} +\newcommand{\acronym}[1]{{\normalfont\textsc{\lowercase{#1}}}} +\newcommand{\strong}[1]{{\normalfont\fontseries{b}\selectfont #1}} +\let\pkg=\strong +\RequirePackage{alltt} +\newenvironment{example}{\begin{alltt}}{\end{alltt}} +\newenvironment{smallexample}{\begin{alltt}\small}{\end{alltt}} +\newenvironment{display}{\list{}{}\item\relax}{\endlist} +\newenvironment{smallverbatim}{\small\verbatim}{\endverbatim} +\providecommand{\operatorname}[1]{% + \mathop{\operator@font#1}\nolimits} +\renewcommand{\P}{% + \mathop{\operator@font I\hspace{-1.5pt}P\hspace{.13pt}}} +\newcommand{\E}{% + \mathop{\operator@font I\hspace{-1.5pt}E\hspace{.13pt}}} +\newcommand{\VAR}{\operatorname{var}} +\newcommand{\COV}{\operatorname{cov}} +\newcommand{\COR}{\operatorname{cor}} +\RequirePackage{amsfonts} +\endinput +%% +%% End of file `Rnews.sty'. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 16:59:47
|
Revision: 1793 http://sourceforge.net/p/r-gregmisc/code/1793 Author: warnes Date: 2014-04-05 16:59:43 +0000 (Sat, 05 Apr 2014) Log Message: ----------- The issue Brian pointed out was an error in the isUnknown() code, not an error in the unit tests! Modified Paths: -------------- trunk/gdata/R/unknown.R trunk/gdata/tests/unitTests/runit.unknown.R Modified: trunk/gdata/R/unknown.R =================================================================== --- trunk/gdata/R/unknown.R 2014-04-05 15:55:48 UTC (rev 1792) +++ trunk/gdata/R/unknown.R 2014-04-05 16:59:43 UTC (rev 1793) @@ -29,7 +29,14 @@ } else { unknown <- as.character(x=unknown, ...) } - isUnknown.default(x=as.character(x), unknown=unknown) + + if(is.list(x) && !inherits(x=x, what="POSIXlt")) { + x <- lapply(x, FUN=as.character, ...) + } else { + x <- as.character(x=x, ...) + } + + isUnknown.default(x=as.character(x), unknown=as.character(unknown)) } isUnknown.list <- function(x, unknown=NA, ...) { Modified: trunk/gdata/tests/unitTests/runit.unknown.R =================================================================== --- trunk/gdata/tests/unitTests/runit.unknown.R 2014-04-05 15:55:48 UTC (rev 1792) +++ trunk/gdata/tests/unitTests/runit.unknown.R 2014-04-05 16:59:43 UTC (rev 1793) @@ -249,42 +249,7 @@ ## Date-time classes checkIdentical(isUnknown(xDateUnk, unknown=dateUnk), xDateTest) checkIdentical(isUnknown(xDate1Unk, unknown=dateUnk), xDate1Test) - - #### - ## Per Brian Ripley on 2014-01-15: - ## - ## On platforms where POSIXlt has a gmtoff component, it does not - ## need to be set. So - ## - ## > z$gmtoff - ## [1] 3600 NA - ## > xPOSIXltUnk$gmtoff - ## [1] 3600 3600 - ## - ## (or sometimes 0, not NA). - ## - ## So although identical() correctly reports that they differ, this - ## is allowed for optional components. - ## - ## It would also be wrong to use identical() to compare isdst - ## components: isdst = -1 means unknown. - ## - ## Replaced: - ## checkIdentical(isUnknown(xPOSIXltUnk, unknown=POSIXltUnk), xPOSIXltTest) - ## With: - tmp_isUnknown <- isUnknown(xPOSIXltUnk, unknown=POSIXltUnk) - tmp_xPOSIXltTest <- xPOSIXlt - - tmp_isUnknown$gmtoff <- NULL # Remove $gmtoff to avoid comparison - tmp_xPOSIXltTest$gmtoff <- NULL - - tmp_isUnknownisdst <- NULL # Remove $isdst to avoid comparison - tmp_xPOSIXltTest$isdst <- NULL - - checkIdentical(tmp_isUnknown, tmp_xPOSIXltTest) - ## - #### - + checkIdentical(isUnknown(xPOSIXltUnk, unknown=POSIXltUnk), xPOSIXltTest) checkIdentical(isUnknown(xPOSIXlt1Unk, unknown=POSIXltUnk), xPOSIXlt1Test) checkIdentical(isUnknown(xPOSIXctUnk, unknown=POSIXctUnk), xPOSIXctTest) checkIdentical(isUnknown(xPOSIXct1Unk, unknown=POSIXctUnk), xPOSIXct1Test) @@ -366,41 +331,9 @@ ## Date-time classes checkIdentical(unknownToNA(xDateUnk, unknown=dateUnk), xDate) + checkIdentical(unknownToNA(xPOSIXltUnk, unknown=POSIXltUnk), xPOSIXlt) checkIdentical(unknownToNA(xPOSIXctUnk, unknown=POSIXctUnk), xPOSIXct) - #### - ## Per Brian Ripley on 2014-01-15: - ## - ## On platforms where POSIXlt has a gmtoff component, it does not need to be set. So - ## - ## > z$gmtoff - ## [1] 3600 NA - ## > xPOSIXltUnk$gmtoff - ## [1] 3600 3600 - ## - ## (or sometimes 0, not NA). - ## - ## So although identical() correctly reports that they differ, this - ## is allowed for optional components. - ## - ## It would also be wrong to use identical() to compare isdst - ## components: isdst = -1 means unknown. - ## - ## Replaced: - ## checkIdentical(unknownToNA(xPOSIXltUnk, unknown=POSIXltUnk), xPOSIXlt) - ## With: - tmp_unknownToNA <- unknownToNA(xPOSIXltUnk, unknown=POSIXltUnk) - tmp_xPOSIXlt <- xPOSIXlt - - tmp_unknownToNA$gmtoff <- NULL # Remove $gmtoff to avoid comparison - tmp_xPOSIXlt$gmtoff <- NULL - - tmp_unknownToNA$isdst <- NULL # Remove $isdst to avoid comparison - tmp_xPOSIXlt$isdst <- NULL - - checkIdentical(tmp_unknownToNA, tmp_xPOSIXlt) - #### - ## --- lists and data.frames --- ## with vector of single unknown values This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 15:55:51
|
Revision: 1792 http://sourceforge.net/p/r-gregmisc/code/1792 Author: warnes Date: 2014-04-05 15:55:48 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Apply changes Brian recommned to NAtoUnknown as well as unknownToNA. Modified Paths: -------------- trunk/gdata/tests/unitTests/runit.unknown.R Modified: trunk/gdata/tests/unitTests/runit.unknown.R =================================================================== --- trunk/gdata/tests/unitTests/runit.unknown.R 2014-04-05 14:40:08 UTC (rev 1791) +++ trunk/gdata/tests/unitTests/runit.unknown.R 2014-04-05 15:55:48 UTC (rev 1792) @@ -249,7 +249,42 @@ ## Date-time classes checkIdentical(isUnknown(xDateUnk, unknown=dateUnk), xDateTest) checkIdentical(isUnknown(xDate1Unk, unknown=dateUnk), xDate1Test) - checkIdentical(isUnknown(xPOSIXltUnk, unknown=POSIXltUnk), xPOSIXltTest) + + #### + ## Per Brian Ripley on 2014-01-15: + ## + ## On platforms where POSIXlt has a gmtoff component, it does not + ## need to be set. So + ## + ## > z$gmtoff + ## [1] 3600 NA + ## > xPOSIXltUnk$gmtoff + ## [1] 3600 3600 + ## + ## (or sometimes 0, not NA). + ## + ## So although identical() correctly reports that they differ, this + ## is allowed for optional components. + ## + ## It would also be wrong to use identical() to compare isdst + ## components: isdst = -1 means unknown. + ## + ## Replaced: + ## checkIdentical(isUnknown(xPOSIXltUnk, unknown=POSIXltUnk), xPOSIXltTest) + ## With: + tmp_isUnknown <- isUnknown(xPOSIXltUnk, unknown=POSIXltUnk) + tmp_xPOSIXltTest <- xPOSIXlt + + tmp_isUnknown$gmtoff <- NULL # Remove $gmtoff to avoid comparison + tmp_xPOSIXltTest$gmtoff <- NULL + + tmp_isUnknownisdst <- NULL # Remove $isdst to avoid comparison + tmp_xPOSIXltTest$isdst <- NULL + + checkIdentical(tmp_isUnknown, tmp_xPOSIXltTest) + ## + #### + checkIdentical(isUnknown(xPOSIXlt1Unk, unknown=POSIXltUnk), xPOSIXlt1Test) checkIdentical(isUnknown(xPOSIXctUnk, unknown=POSIXctUnk), xPOSIXctTest) checkIdentical(isUnknown(xPOSIXct1Unk, unknown=POSIXctUnk), xPOSIXct1Test) @@ -333,6 +368,7 @@ checkIdentical(unknownToNA(xDateUnk, unknown=dateUnk), xDate) checkIdentical(unknownToNA(xPOSIXctUnk, unknown=POSIXctUnk), xPOSIXct) + #### ## Per Brian Ripley on 2014-01-15: ## ## On platforms where POSIXlt has a gmtoff component, it does not need to be set. So @@ -350,6 +386,9 @@ ## It would also be wrong to use identical() to compare isdst ## components: isdst = -1 means unknown. ## + ## Replaced: + ## checkIdentical(unknownToNA(xPOSIXltUnk, unknown=POSIXltUnk), xPOSIXlt) + ## With: tmp_unknownToNA <- unknownToNA(xPOSIXltUnk, unknown=POSIXltUnk) tmp_xPOSIXlt <- xPOSIXlt @@ -360,8 +399,8 @@ tmp_xPOSIXlt$isdst <- NULL checkIdentical(tmp_unknownToNA, tmp_xPOSIXlt) + #### - ## --- lists and data.frames --- ## with vector of single unknown values This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 14:40:11
|
Revision: 1791 http://sourceforge.net/p/r-gregmisc/code/1791 Author: warnes Date: 2014-04-05 14:40:08 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Update NEWS file Modified Paths: -------------- trunk/gdata/inst/NEWS Modified: trunk/gdata/inst/NEWS =================================================================== --- trunk/gdata/inst/NEWS 2014-04-05 14:38:45 UTC (rev 1790) +++ trunk/gdata/inst/NEWS 2014-04-05 14:40:08 UTC (rev 1791) @@ -8,8 +8,9 @@ Other Changes -- Unit tests now follow R standard practice +- 'aggregate.table' is now defunct. See '?gdata-defunct' for details. +- Unit tests and vignettes now follow R standard practice. Changes in 2.13.2 (2013-06-28) ------------------------------ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 14:38:48
|
Revision: 1790 http://sourceforge.net/p/r-gregmisc/code/1790 Author: warnes Date: 2014-04-05 14:38:45 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Don't need latex .dtx source file Removed Paths: ------------- trunk/gdata/inst/doc/Rnews.dtx Deleted: trunk/gdata/inst/doc/Rnews.dtx =================================================================== --- trunk/gdata/inst/doc/Rnews.dtx 2014-04-05 14:26:49 UTC (rev 1789) +++ trunk/gdata/inst/doc/Rnews.dtx 2014-04-05 14:38:45 UTC (rev 1790) @@ -1,574 +0,0 @@ -\def\fileversion{v0.3.1} -\def\filename{Rnews} -\def\filedate{2001/09/04} -\def\docdate {2001/09/04} -% -% \iffalse -% -%% -%% Package `Rnews' to use with LaTeX2e -%% Copyright (C) 2001 by the R Core Development Team -%% Please report errors to KH or FL -%% -%% -*- LaTeX -*- -% -% \fi -% -% \iffalse -% \changes{v0.1}{2001/01/05}{First draft.} -% \changes{v0.2}{2001/07/01} -% {Added macros \cmd\P, \cmd\E, \cmd\VAR, \cmd\COV, \cmd\COR, and -% \cmd\operatorname. Require \pkg{amsfonts} to produce symbols for -% sets of positive integers etc.} -% \changes{v0.3}{2001/08/02} -% {Add package option `driver' for typesetting the driver. -% Change article environment to use chapters. -% Ensure unique figure labels.} -% \changes{v0.3.1}{2001/09/04} -% {Remove redefinition of |\caption|, which had figures hard-wired. -% Instead, have our |figure| environment set |\@captype|.} -% \fi -% -% \MakeShortVerb{\|} -% -% \newcommand{\AmS}{$${\protect\the\textfont2 A}\kern-.1667em\lower -% .5ex\hbox{\protect\the\textfont2 M}\kern -% -.125em{\protect\the\textfont2 S}} -% \newcommand{\AmSLaTeX}{\mbox{\AmS-\LaTeX}} -% -% \title{The package \pkg{\filename}} -% \author{Kurt Hornik \and Friedrich Leisch} -% -% \maketitle -% -% \section{Introduction} -% -% The \LaTeXe{} package \pkg{\filename} provides commands for formatting -% the R Newsletter. -% -% \section{Documentation} -% -% \subsection{Marking Words and Phrases} -% -% The \pkg{Rnews} package provides roughly the same commands for marking -% words and phrases as does Texinfo (but note that the \LaTeX special -% characters still need special treatment). These commands are -% \begin{description} -% \item[\code{\cmd{\code}\{\var{sample-code}\}}] -% Indicate text that is a literal example of a piece of a program. -% \item[\code{\cmd{\kbd}\{\var{keyboard-characters}\}}] -% Indicate keyboard input. -% \item[\code{\cmd{\key}\{\var{key-name}\}}] -% Indicate the conventional name for a key on a keyboard. -% \item[\code{\cmd{\samp}\{\var{text}\}}] -% Indicate text that is a literal example of a sequence of -% characters. -% \item[\code{\cmd{\var}\{\var{metasyntactic-variable}\}}] -% Indicate a metasyntactic variable. -% \item[\code{\cmd{\env}\{\var{environment-variable}\}}] -% Indicate an environment variable. -% \item[\code{\cmd{\file}\{\var{file-name}\}}] -% Indicate the name of a file. -% \item[\code{\cmd{\command}\{\var{command-name}\}}] -% Indicate a command name (such as \samp{ls}). -% \item[\code{\cmd{\option}\{\var{option-name}\}}] -% Indicate a command line option. -% \item[\code{\cmd{\dfn}\{\var{term}\}}] -% Indicate the introductory or defining use of a term. -% \item[\code{\cmd{\acronym}\{\var{acronym}\}}] -% Use for abbreviattions written in all capital letters, such as -% \samp{NASA}. -% \end{description} -% If this sounds rather confusing, please see the Texinfo documentation -% for more details. -% -% \DescribeMacro{\strong} -% There is also a |\strong| command for emphasizing text more strongly -% than with |\emph|. For example, |\strong{Note:}| gives \strong{Note:}. -% -% \DescribeMacro{\pkg} -% Finally, use |\pkg| for indicating R packages. -% -% \subsection{Quotations and Examples} -% -% In addition to the standard \LaTeX{} for quotations and examples (such -% as |quote|, |quotation|, |flushleft|, |center| and |flushright|), the -% \pkg{\filename} package provides the following environments. -% \begin{description} -% \item[\code{example}] -% Illustrate code, commands, and the like. The text is printed in a -% fixed-width font, and indented but not filled. -% \item[\code{smallexample}] -% Similar to \code{example}, except that text is typeset in a smaller -% font. -% \end{description} -% -% \subsection{Mathematics} -% -% \DescribeMacro{\P} -% \DescribeMacro{\E} -% \DescribeMacro{\VAR} -% \DescribeMacro{\COV} -% \DescribeMacro{\COR} -% The commands |\P|, |\E|, |\VAR|, |\COV|, and |\COR| produce symbols -% for probability, expectation, variance, covariance and correlation. -% For example, Chebyshev's inequality -% \DeleteShortVerb{\|} -% \begin{displaymath} -% \P(|\xi-\E\xi|>\lambda) \le \frac{\VAR(\xi)}{\lambda^2}. -% \end{displaymath} -% can be coded as -% \MakeShortVerb{\|} -% \begin{quote} -% \verb+\P(|\xi-\E\xi|>\lambda) \le \frac{\VAR(\xi)}{\lambda^2}+. -% \end{quote} -% -% \DescribeMacro{\mathbb} -% The symbols -% \begin{displaymath} -% \mathbb{N}\quad\mathbb{Z}\quad\mathbb{Q}\quad\mathbb{R}\quad\mathbb{C} -% \end{displaymath} -% for the positive integers, the integers, and the rational, real and -% complex numbers, respectively, can be obtained using |\mathbb| from -% package \pkg{amsfonts} as -% \begin{quote} -% |\mathbb{N}| |\mathbb{Z}| |\mathbb{Q}| |\mathbb{R}| |\mathbb{C}| -% \end{quote} -% -% \section{The Code} -% -% \subsection{The Batch File} -% -% First comes the code for creating the batch file \file{\filename.ins} -% which in turn can be used for producing the package and driver files. -% -% \begin{macrocode} -%<*install> -\begin{filecontents}{\filename.ins} -% Simply TeX or LaTeX this file to extract various files from the source -% file `Rnews.dtx'. - \def\filedate{2001/01/05} \def\batchfile{Rnews.ins} \input - docstrip.tex \preamble -\endpreamble -\generateFile{Rnews.drv}{t}{\from{Rnews.dtx}{driver}} -\generateFile{Rnews.sty}{t}{\from{Rnews.dtx}{package}} -\Msg{***********************************************************} -\Msg{* For documentation, run LaTeX on Rnews.dtx or Rnews.drv. *} -\Msg{***********************************************************} -\end{filecontents} -%</install> -% \end{macrocode} -% -% \subsection{The Driver} -% -% Next comes the documentation driver file for \TeX{}, i.e., the file -% that will produce the documentation you are currently reading. It -% will be extracted from this file by the \texttt{docstrip} program. -% Since it is the first code in the file one can alternatively process -% this file directly with \LaTeXe{} to obtain the documentation. -% -% \begin{macrocode} -%<*driver> -\documentclass[fleqn]{ltxdoc} -\usepackage[driver]{\filename} -\renewcommand{\pkg}[1]{\textsf{#1}} -\begin{document} - \DocInput{\filename.dtx} -\end{document} -%</driver> -% \end{macrocode} -% -% \subsection{The Code} -% -% Now comes the code for the package. -% -% It the current format is not \LaTeXe{}, we abort immediately. -% Otherwise, we provide ourselves and show the current version of the -% package on the screen and in the transscript file. -% \begin{macrocode} -%<*package> -\NeedsTeXFormat{LaTeX2e}[1995/12/01] -\ProvidesPackage{\filename}[\filedate\space\fileversion\space - Rnews package] -\typeout{Package: `\filename\space\fileversion \@spaces <\filedate>'} -\typeout{English documentation as of <\docdate>} -% \end{macrocode} -% -% Next, we set up a more or less trivial option handler. We use option -% `driver' for conditionalizing package code we do not want executed -% when typesetting the driver file. -% \begin{macrocode} -\RequirePackage{ifthen} -\newboolean{Rnews@driver} -\DeclareOption{driver}{\setboolean{Rnews@driver}{true}} -\DeclareOption*{\PackageWarning{\filename}{Unknown option - `\CurrentOption'}} -\ProcessOptions\relax -% \end{macrocode} -% -% Now comes the real code. -% -% \begin{macrocode} -\ifthenelse{\boolean{Rnews@driver}}{}{ -% \end{macrocode} -% -% First we load some utility packages. -% \begin{macrocode} -\RequirePackage{multicol,graphicx,color,fancyhdr,hyperref} -% \end{macrocode} -% -% \subsubsection{Basic Structure} -% -% Issues of of \emph{R News} are created from the standard \LaTeX{} -% document class \pkg{report}. Individual articles correspond to -% chapters, and are contained in |article| environments. This makes it -% easy to have figures counted within articles and hence hyperlinked -% correctly. -% -% Basic front matter information about the issue: volume, number, and -% date. -% \begin{macrocode} -\newcommand{\volume}[1]{\def\Rnews@volume{#1}} -\newcommand{\volnumber}[1]{\def\Rnews@number{#1}} -\renewcommand{\date}[1]{\def\Rnews@date{#1}} -% \end{macrocode} -% -% We do not want numbered sections. -% \begin{macrocode} -\setcounter{secnumdepth}{-1} -% \end{macrocode} -% -% \begin{macro}{\author} -% \begin{macro}{\title} -% \begin{macro}{\subtitle} -% An article has an author, a title, and optionally a subtitle. We use -% the obvious commands for specifying these. -% \begin{macrocode} -\renewcommand{\author}[1]{\def\Rnews@author{#1}} -\renewcommand{\title}[1]{\def\Rnews@title{#1}} -\newcommand{\subtitle}[1]{\def\Rnews@subtitle{#1}} -% \end{macrocode} -% \end{macro} -% \end{macro} -% \end{macro} -% -% \begin{environment}{article} -% Environment |article| clears the article header information its begin -% and restores single column mode at its end. -% \begin{macrocode} -\newenvironment{article}{% - \author{}\title{}\subtitle{}}{\end{multicols}} -% \end{macrocode} -% \end{environment} -% -% \begin{macro}{\maketitle} -% The real work is done by a redefined version of |\maketitle|, which -% also switches to double column mode. Note that even though we do not -% want chapters (articles) numbered, we need to increment the chapter -% counter, so that figures get correct labelling. -% \begin{macrocode} -\renewcommand{\maketitle}{ - \chapter{\Rnews@title} - \refstepcounter{chapter} - \begin{multicols}{2} - \ifx\empty\Rnews@subtitle\else\par\addvspace{\baselineskip} - \noindent\textbf{\Rnews@subtitle}\fi - \ifx\empty\Rnews@author\else\par\addvspace{\baselineskip} - \noindent\textit{\Rnews@author}\fi} -% \end{macrocode} -% \end{macro} -% -% Now for some ugly redefinitions. We do not want articles to start a -% new page. -% \begin{macrocode} -\renewcommand\chapter{\secdef\@chapter\@schapter} -% \end{macrocode} -% TOC entries for articles (chapters) should really look like sections. -% \begin{macrocode} -\renewcommand*\l@chapter{\@dottedtocline{0}{0pt}{1em}} -% \end{macrocode} -% We need to adjust vertical spacing in |\@makechapterhead|: extra space -% before the title only if not at the beginning, no extra space after -% it. -% \begin{macrocode} -\def\@makechapterhead#1{% - \addvspace{2\baselineskip}% - {\parindent \z@ \raggedright \normalfont - \ifnum \c@secnumdepth >\m@ne - \huge\bfseries \@chapapp\space \thechapter - \par\nobreak - \vskip 20\p@ - \fi - \interlinepenalty\@M - \Huge \bfseries #1\par\nobreak}} -% \end{macrocode} -% We want bibliographies as starred sections within articles. As the -% standard |thebibliography| environment uses |chapter*|, we simply -% redefine the latter according to our needs. -% \begin{macrocode} -\def\@schapter#1{\section*#1} -% \end{macrocode} -% -% Package \pkg{multicol}, which is used for producing two-column output, -% only allows for starred (single-column) floats (figures and tables). -% Therefore, we provide a simple non-floating |figure| environment -% ourselves. -% \begin{macrocode} -\renewenvironment{figure}[1][]{% - \def\@captype{figure} - \begin{minipage}{0.9\columnwidth}}{ - \end{minipage}\par\addvspace{\baselineskip}} -% \end{macrocode} -% Equations, figures and tables are counted within articles, but we do -% not show the article number. -% \begin{macrocode} -\renewcommand{\theequation}{\@arabic\c@equation} -\renewcommand{\thefigure}{\@arabic\c@figure} -\renewcommand{\thetable}{\@arabic\c@table} -% \end{macrocode} -% -% \begin{macro}{\tableofcontents} -% Need to provide our own version of |\tableofcontents| (no fiddling -% with the number of columns). Note that |\section*| is really the same -% as |\chapter*|). -% \begin{macrocode} -\renewcommand{\contentsname}{Contents of this issue:} -\renewcommand\tableofcontents{% - \section*{\contentsname - \@mkboth{% - \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}% - \@starttoc{toc}} -% \end{macrocode} -% \end{macro} -% \begin{macro}{\titlepage} -% The title page of each issue features logo et al at the top and the -% TOC. We start with the top. -% \begin{macrocode} -\renewcommand{\titlepage}{% - \noindent - \rule{\textwidth}{1pt}\\[-.8\baselineskip] - \rule{\textwidth}{.5pt} - \begin{center} - \includegraphics[height=2cm]{Rlogo}\hspace{7mm} - \fontsize{2cm}{2cm}\selectfont - News - \end{center} - The Newsletter of the R Project\hfill - Volume \Rnews@volume/\Rnews@number, \Rnews@date\\[-.5\baselineskip] - \rule{\textwidth}{.5pt}\\[-.8\baselineskip] - \rule{\textwidth}{1pt} - \vspace{1cm} -% \end{macrocode} -% Now set up the header and footer information for the rest of the -% document. -% \begin{macrocode} - \fancyhf{} - \fancyhead[L]{Vol.~\Rnews@volume/\Rnews@number, \Rnews@date} - \fancyhead[R]{\thepage} - \fancyfoot[L]{R News} - \fancyfoot[R]{ISSN 1609-3631} - \thispagestyle{empty} -% \end{macrocode} -% And finally, put the TOC at the bottom in a framed box. Note the way -% |tocdepth| is adjusted before and after producing the TOC: thus, we -% can ensure that only articles show up in the printed TOC, but that in -% the PDF version, bookmarks are created for sections and subsections as -% well (provided that the non-starred forms are used). -% \begin{macrocode} - \begin{bottombox} - \begin{multicols}{2} - \setcounter{tocdepth}{0} - \tableofcontents - \setcounter{tocdepth}{2} - \end{multicols} - \end{bottombox}} -% \end{macrocode} -% \end{macro} -% -% \subsubsection{Layout, Fonts and Color} -% -% \paragraph{Layout.} -% We set the basic layout parameters in a way that printouts should be -% fine for both A4 and Letter paper. -% \begin{macrocode} -\setlength{\textheight}{250mm} -\setlength{\topmargin}{-10mm} -\setlength{\textwidth}{17cm} -\setlength{\oddsidemargin}{-6mm} -\setlength{\columnseprule}{.1pt} -\setlength{\columnsep}{20pt} -% \end{macrocode} -% -% \paragraph{Fonts.} -% We use the following fonts (all with T1 encoding): -% \begin{center} -% \begin{tabular}{lp{0.8\textwidth}} -% rm & palatino \\ -% tt & almost european (computer modern working with T1) \\ -% & Reason for aett: uses less horizontal space than courier, -% which is better for example code \\ -% sf & almost european \\ -% math & palatino -% \end{tabular} -% \end{center} -% -% \begin{macrocode} -\RequirePackage{ae,mathpple} -\RequirePackage[T1]{fontenc} -\renewcommand{\rmdefault}{ppl} -\renewcommand{\sfdefault}{aess} -\renewcommand{\ttdefault}{aett} -% \end{macrocode} -% -% \paragraph{Colors.} These are actually used for |\hypersetup| but we -% do not call this here, although we should. -% \marginpar{FIXME} -% \begin{macrocode} -\definecolor{Red}{rgb}{0.7,0,0} -\definecolor{Blue}{rgb}{0,0,0.8} -\definecolor{hellgrau}{rgb}{0.55,0.55,0.55} -% \end{macrocode} -% -% \subsubsection{Miscellania} -% -% \begin{macrocode} -\newcommand{\R}{R} -\newcommand{\address}[1]{\addvspace{\baselineskip}\noindent\emph{#1}} -\newcommand{\email}[1]{\href{mailto:#1}{\normalfont\texttt{#1}}} -% \end{macrocode} -% -% \begin{environment}{bottombox} -% Used for creating the TOC and the back matter editorial information. -% \begin{macrocode} -\newsavebox{\Rnews@box} -\newlength{\Rnews@len} -\newenvironment{bottombox}{% - \begin{figure*}[b] - \begin{center} - \noindent - \begin{lrbox}{\Rnews@box} - \begin{minipage}{0.99\textwidth}}{% - \end{minipage} - \end{lrbox} - \addtolength{\Rnews@len}{\fboxsep} - \addtolength{\Rnews@len}{\fboxrule} - \hspace*{-\Rnews@len}\fbox{\usebox{\Rnews@box}} - \end{center} - \end{figure*}} -% \end{macrocode} -% \end{environment} -% -% \begin{environment}{boxedverbatim} -% This does not seem to be used any more. -% \marginpar{FIXME} -% \begin{macrocode} -\newenvironment{boxedverbatim}{% - \begin{lrbox}{\Rnews@box} - \begin{smallverbatim}}{% - \end{smallverbatim} - \end{lrbox} - \hspace*{-\fboxsep}\fbox{\usebox{\Rnews@box}}} -% \end{macrocode} -% \end{environment} -% -% Finally, we turn on fancy page style. -% \begin{macrocode} -\pagestyle{fancy} -} % \ifthenelse{\boolean{Rnews@driver}} -% \end{macrocode} -% -% \subsubsection{Marking Words and Phrases} -% -% Simple font selection is not good enough. For example, |\texttt{--}| -% gives `\texttt{--}', i.e., an endash in typewriter font. Hence, we -% need to turn off ligatures, which currently only happens for commands -% |\code| and |\samp| and the ones derived from them. Hyphenation is -% another issue; it should really be turned off inside |\samp|. And -% most importantly, \LaTeX{} special characters are a nightmare. E.g., -% one needs |\~{}| to produce a tilde in a file name marked by |\file|. -% Perhaps a few years ago, most users would have agreed that this may be -% unfortunate but should not be changed to ensure consistency. But with -% the advent of the WWW and the need for getting `|~|' and `|#|' into -% URLs, commands which only treat the escape and grouping characters -% specially have gained acceptance (in fact, this is also what -% \pkg{alltt} does, and hence environments based on it such as our -% |smallexample|). Hence, in the long run we should implement the same -% for |\code|, |\kbd|, |\samp|, |\var|, and |\file|. (The other -% Texinfo-style commands do not need this.) -% -% \begin{macrocode} -%\newcommand\code{\bgroup\@noligs\@codex} -\newcommand\code{\bgroup\@codex} -\def\@codex#1{{\normalfont\ttfamily\hyphenchar\font=-1 #1}\egroup} -\newcommand{\kbd}[1]{{\normalfont\texttt{#1}}} -\newcommand{\key}[1]{{\normalfont\texttt{\uppercase{#1}}}} -\newcommand\samp{`\bgroup\@noligs\@sampx} -\def\@sampx#1{{\normalfont\texttt{#1}}\egroup'} -\newcommand{\var}[1]{{\normalfont\textsl{#1}}} -\let\env=\code -\newcommand{\file}[1]{{`\normalfont\textsf{#1}'}} -\let\command=\code -\let\option=\samp -\newcommand{\dfn}[1]{{\normalfont\textsl{#1}}} -\newcommand{\acronym}[1]{{\normalfont\textsc{\lowercase{#1}}}} -\newcommand{\strong}[1]{{\normalfont\fontseries{b}\selectfont #1}} -\let\pkg=\strong -% \end{macrocode} -% -% \subsubsection{Quotations and Examples} -% -% \begin{macrocode} -\RequirePackage{alltt} -\newenvironment{example}{\begin{alltt}}{\end{alltt}} -\newenvironment{smallexample}{\begin{alltt}\small}{\end{alltt}} -\newenvironment{display}{\list{}{}\item\relax}{\endlist} -% \end{macrocode} -% -% \subsubsection{Mathematics} -% -% \begin{macro}{\operatorname} -% The implementation of |\operatorname| is similar to the mechanism -% \LaTeXe{} uses for functions like sin and cos, and simpler than the -% one of \AmSLaTeX{}. We use |\providecommand| for the definition in -% order to keep the one of the \pkg{amstex} if this package has -% already been loaded. -% \begin{macrocode} -\providecommand{\operatorname}[1]{% - \mathop{\operator@font#1}\nolimits} -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\P} -% \begin{macro}{\E} -% \begin{macro}{\VAR} -% \begin{macro}{\COV} -% \begin{macro}{\COR} -% Next, we provide commands for probability, expectation, variance, -% covariance and correlation which are obviously useful in probability -% theory and statistics. -% (Of course, originally |\P| gives \mathhexbox27B.) -% \begin{macrocode} -\renewcommand{\P}{% - \mathop{\operator@font I\hspace{-1.5pt}P\hspace{.13pt}}} -\newcommand{\E}{% - \mathop{\operator@font I\hspace{-1.5pt}E\hspace{.13pt}}} -\newcommand{\VAR}{\operatorname{var}} -\newcommand{\COV}{\operatorname{cov}} -\newcommand{\COR}{\operatorname{cor}} -% \end{macrocode} -% \end{macro} -% \end{macro} -% \end{macro} -% \end{macro} -% \end{macro} -% -% Finally, we load package \pkg{amsfonts} so that |\mathbb| is available -% for producing the symbols for positive integers etc. -% \begin{macrocode} -\RequirePackage{amsfonts} -% \end{macrocode} -% -% This ends the implementation of the \pkg{\filename} package. -% \begin{macrocode} -%</package> -% \end{macrocode} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 14:26:54
|
Revision: 1789 http://sourceforge.net/p/r-gregmisc/code/1789 Author: warnes Date: 2014-04-05 14:26:49 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Move vignettes from inst/doc/ to vignettes/ Added Paths: ----------- trunk/gdata/vignettes/ trunk/gdata/vignettes/mapLevels.Rnw trunk/gdata/vignettes/unknown.Rnw Removed Paths: ------------- trunk/gdata/inst/doc/mapLevels.Rnw trunk/gdata/inst/doc/unknown.Rnw Deleted: trunk/gdata/inst/doc/mapLevels.Rnw =================================================================== --- trunk/gdata/inst/doc/mapLevels.Rnw 2014-04-05 13:57:10 UTC (rev 1788) +++ trunk/gdata/inst/doc/mapLevels.Rnw 2014-04-05 14:26:49 UTC (rev 1789) @@ -1,229 +0,0 @@ - -%\VignetteIndexEntry{Mapping levels of a factor} -%\VignettePackage{gdata} -%\VignetteKeywords{levels, factor, manip} - -\documentclass[a4paper]{report} -\usepackage{Rnews} -\usepackage[round]{natbib} -\bibliographystyle{abbrvnat} - -\usepackage{Sweave} -\SweaveOpts{strip.white=all, keep.source=TRUE} - -\begin{document} - -\begin{article} - -\title{Mapping levels of a factor} -\subtitle{The \pkg{gdata} package} -\author{by Gregor Gorjanc} - -\maketitle - -\section{Introduction} - -Factors use levels attribute to store information on mapping between -internal integer codes and character values i.e. levels. First level is -mapped to internal integer code 1 and so on. Although some users do not -like factors, their use is more efficient in terms of storage than for -character vectors. Additionally, there are many functions in base \R{} that -provide additional value for factors. Sometimes users need to work with -internal integer codes and mapping them back to factor, especially when -interfacing external programs. Mapping information is also of interest if -there are many factors that should have the same set of levels. This note -describes \code{mapLevels} function, which is an utility function for -mapping the levels of a factor in \pkg{gdata} \footnote{from version 2.3.1} -package \citep{WarnesGdata}. - -\section{Description with examples} - -Function \code{mapLevels()} is an (S3) generic function and works on -\code{factor} and \code{character} atomic classes. It also works on -\code{list} and \code{data.frame} objects with previously mentioned atomic -classes. Function \code{mapLevels} produces a so called ``map'' with names -and values. Names are levels, while values can be internal integer codes or -(possibly other) levels. This will be clarified later on. Class of this -``map'' is \code{levelsMap}, if \code{x} in \code{mapLevels()} was atomic -or \code{listLevelsMap} otherwise - for \code{list} and \code{data.frame} -classes. The following example shows the creation and printout of such a -``map''. - -<<ex01>>= -library(gdata) -(fac <- factor(c("B", "A", "Z", "D"))) -(map <- mapLevels(x=fac)) -@ - -If we have to work with internal integer codes, we can transform factor to -integer and still get ``back the original factor'' with ``map'' used as -argument in \code{mapLevels<-} function as shown bellow. \code{mapLevels<-} -is also an (S3) generic function and works on same classes as -\code{mapLevels} plus \code{integer} atomic class. - -<<ex02>>= -(int <- as.integer(fac)) -mapLevels(x=int) <- map -int -identical(fac, int) -@ - -Internally ``map'' (\code{levelsMap} class) is a \code{list} (see bellow), -but its print method unlists it for ease of inspection. ``Map'' from -example has all components of length 1. This is not mandatory as -\code{mapLevels<-} function is only a wrapper around workhorse function -\code{levels<-} and the later can accept \code{list} with components of -various lengths. - -<<ex03>>= -str(map) -@ - -Although not of primary importance, this ``map'' can also be used to remap -factor levels as shown bellow. Components ``later'' in the map take over -the ``previous'' ones. Since this is not optimal I would rather recommend -other approaches for ``remapping'' the levels of a \code{factor}, say -\code{recode} in \pkg{car} package \citep{FoxCar}. - -<<ex04>>= -map[[2]] <- as.integer(c(1, 2)) -map -int <- as.integer(fac) -mapLevels(x=int) <- map -int -@ - -Up to now examples showed ``map'' with internal integer codes for values -and levels for names. I call this integer ``map''. On the other hand -character ``map'' uses levels for values and (possibly other) levels for -names. This feature is a bit odd at first sight, but can be used to easily -unify levels and internal integer codes across several factors. Imagine -you have a factor that is for some reason split into two factors \code{f1} -and \code{f2} and that each factor does not have all levels. This is not -uncommon situation. - -<<ex05>>= -(f1 <- factor(c("A", "D", "C"))) -(f2 <- factor(c("B", "D", "C"))) -@ - -If we work with this factors, we need to be careful as they do not have the -same set of levels. This can be solved with appropriately specifying -\code{levels} argument in creation of factors i.e. \code{levels=c("A", "B", - "C", "D")} or with proper use of \code{levels<-} function. I say proper -as it is very tempting to use: - -<<ex06>>= -fTest <- f1 -levels(fTest) <- c("A", "B", "C", "D") -fTest -@ - -Above example extends set of levels, but also changes level of 2nd and 3rd -element in \code{fTest}! Proper use of \code{levels<-} (as shown in -\code{levels} help page) would be: - -<<ex07>>= -fTest <- f1 -levels(fTest) <- list(A="A", B="B", - C="C", D="D") -fTest -@ - -Function \code{mapLevels} with character ``map'' can help us in such -scenarios to unify levels and internal integer codes across several -factors. Again the workhorse under this process is \code{levels<-} function -from base \R{}! Function \code{mapLevels<-} just controls the assignment of -(integer or character) ``map'' to \code{x}. Levels in \code{x} that match -``map'' values (internal integer codes or levels) are changed to ``map'' -names (possibly other levels) as shown in \code{levels} help page. Levels -that do not match are converted to \code{NA}. Integer ``map'' can be -applied to \code{integer} or \code{factor}, while character ``map'' can be -applied to \code{character} or \code{factor}. Result of \code{mapLevels<-} -is always a \code{factor} with possibly ``remapped'' levels. - -To get one joint character ``map'' for several factors, we need to put -factors in a \code{list} or \code{data.frame} and use arguments -\code{codes=FALSE} and \code{combine=TRUE}. Such map can then be used to -unify levels and internal integer codes. - -<<ex08>>= -(bigMap <- mapLevels(x=list(f1, f2), - codes=FALSE, - combine=TRUE)) -mapLevels(f1) <- bigMap -mapLevels(f2) <- bigMap -f1 -f2 -cbind(as.character(f1), as.integer(f1), - as.character(f2), as.integer(f2)) -@ - -If we do not specify \code{combine=TRUE} (which is the default behaviour) -and \code{x} is a \code{list} or \code{data.frame}, \code{mapLevels} -returns ``map'' of class \code{listLevelsMap}. This is internally a -\code{list} of ``maps'' (\code{levelsMap} objects). Both -\code{listLevelsMap} and \code{levelsMap} objects can be passed to -\code{mapLevels<-} for \code{list}/\code{data.frame}. Recycling occurs when -length of \code{listLevelsMap} is not the same as number of -components/columns of a \code{list}/\code{data.frame}. - -Additional convenience methods are also implemented to ease the work with -``maps'': - -\begin{itemize} - -\item \code{is.levelsMap}, \code{is.listLevelsMap}, \code{as.levelsMap} and - \code{as.listLevelsMap} for testing and coercion of user defined - ``maps'', - -\item \code{"["} for subsetting, - -\item \code{c} for combining \code{levelsMap} or \code{listLevelsMap} - objects; argument \code{recursive=TRUE} can be used to coerce - \code{listLevelsMap} to \code{levelsMap}, for example \code{c(llm1, llm2, - recursive=TRUE)} and - -\item \code{unique} and \code{sort} for \code{levelsMap}. - -\end{itemize} - -\section{Summary} - -Functions \code{mapLevels} and \code{mapLevels<-} can help users to map -internal integer codes to factor levels and unify levels as well as -internal integer codes among several factors. I welcome any comments or -suggestions. - -% \bibliography{refs} -\begin{thebibliography}{1} -\providecommand{\natexlab}[1]{#1} -\providecommand{\url}[1]{\texttt{#1}} -\expandafter\ifx\csname urlstyle\endcsname\relax - \providecommand{\doi}[1]{doi: #1}\else - \providecommand{\doi}{doi: \begingroup \urlstyle{rm}\Url}\fi - -\bibitem[Fox(2006)]{FoxCar} -J.~Fox. -\newblock \emph{car: Companion to Applied Regression}, 2006. -\newblock URL \url{http://socserv.socsci.mcmaster.ca/jfox/}. -\newblock R package version 1.1-1. - -\bibitem[Warnes(2006)]{WarnesGdata} -G.~R. Warnes. -\newblock \emph{gdata: Various R programming tools for data manipulation}, - 2006. -\newblock URL - \url{http://cran.r-project.org/src/contrib/Descriptions/gdata.html}. -\newblock R package version 2.3.1. Includes R source code and/or documentation - contributed by Ben Bolker, Gregor Gorjanc and Thomas Lumley. - -\end{thebibliography} - -\address{Gregor Gorjanc\\ - University of Ljubljana, Slovenia\\ -\email{gre...@bf...}} - -\end{article} - -\end{document} Deleted: trunk/gdata/inst/doc/unknown.Rnw =================================================================== --- trunk/gdata/inst/doc/unknown.Rnw 2014-04-05 13:57:10 UTC (rev 1788) +++ trunk/gdata/inst/doc/unknown.Rnw 2014-04-05 14:26:49 UTC (rev 1789) @@ -1,272 +0,0 @@ - -%\VignetteIndexEntry{Working with Unknown Values} -%\VignettePackage{gdata} -%\VignetteKeywords{unknown, missing, manip} - -\documentclass[a4paper]{report} -\usepackage{Rnews} -\usepackage[round]{natbib} -\bibliographystyle{abbrvnat} - -\usepackage{Sweave} -\SweaveOpts{strip.white=all, keep.source=TRUE} - -\begin{document} - -\begin{article} - -\title{Working with Unknown Values} -\subtitle{The \pkg{gdata} package} -\author{by Gregor Gorjanc} - -\maketitle - -This vignette has been published as \cite{Gorjanc}. - -\section{Introduction} - -Unknown or missing values can be represented in various ways. For example -SAS uses \code{.}~(dot), while \R{} uses \code{NA}, which we can read as -Not Available. When we import data into \R{}, say via \code{read.table} or -its derivatives, conversion of blank fields to \code{NA} (according to -\code{read.table} help) is done for \code{logical}, \code{integer}, -\code{numeric} and \code{complex} classes. Additionally, the -\code{na.strings} argument can be used to specify values that should also -be converted to \code{NA}. Inversely, there is an argument \code{na} in -\code{write.table} and its derivatives to define value that will replace -\code{NA} in exported data. There are also other ways to import/export data -into \R{} as described in the {\emph R Data Import/Export} manual -\citep{RImportExportManual}. However, all approaches lack the possibility -to define unknown value(s) for some particular column. It is possible that -an unknown value in one column is a valid value in another column. For -example, I have seen many datasets where values such as 0, -9, 999 and -specific dates are used as column specific unknown values. - -This note describes a set of functions in package \pkg{gdata}\footnote{ - package version 2.3.1} \citep{WarnesGdata}: \code{isUnknown}, -\code{unknownToNA} and \code{NAToUnknown}, which can help with testing for -unknown values and conversions between unknown values and \code{NA}. All -three functions are generic (S3) and were tested (at the time of writing) -to work with: \code{integer}, \code{numeric}, \code{character}, -\code{factor}, \code{Date}, \code{POSIXct}, \code{POSIXlt}, \code{list}, -\code{data.frame} and \code{matrix} classes. - -\section{Description with examples} - -The following examples show simple usage of these functions on -\code{numeric} and \code{factor} classes, where value \code{0} (beside -\code{NA}) should be treated as an unknown value: - -<<ex01>>= -library("gdata") -xNum <- c(0, 6, 0, 7, 8, 9, NA) -isUnknown(x=xNum) -@ - -The default unknown value in \code{isUnknown} is \code{NA}, which means -that output is the same as \code{is.na} --- at least for atomic -classes. However, we can pass the argument \code{unknown} to define which -values should be treated as unknown: - -<<ex02>>= -isUnknown(x=xNum, unknown=0) -@ - -This skipped \code{NA}, but we can get the expected answer after -appropriately adding \code{NA} into the argument \code{unknown}: - -<<ex03>>= -isUnknown(x=xNum, unknown=c(0, NA)) -@ - -Now, we can change all unknown values to \code{NA} with \code{unknownToNA}. -There is clearly no need to add \code{NA} here. This step is very handy -after importing data from an external source, where many different unknown -values might be used. Argument \code{warning=TRUE} can be used, if there is -a need to be warned about ``original'' \code{NA}s: - -<<ex04>>= -(xNum2 <- unknownToNA(x=xNum, unknown=0)) -@ - -Prior to export from \R{}, we might want to change unknown values -(\code{NA} in \R{}) to some other value. Function \code{NAToUnknown} can be -used for this: - -<<ex05>>= -NAToUnknown(x=xNum2, unknown=999) -@ - -Converting \code{NA} to a value that already exists in \code{x} issues an -error, but \code{force=TRUE} can be used to overcome this if needed. But be -warned that there is no way back from this step: - -<<ex06>>= -NAToUnknown(x=xNum2, unknown=7, force=TRUE) -@ - -Examples below show all peculiarities with class \code{factor}. -\code{unknownToNA} removes \code{unknown} value from levels and inversely -\code{NAToUnknown} adds it with a warning. Additionally, \code{"NA"} is -properly distinguished from \code{NA}. It can also be seen that the -argument \code{unknown} in functions \code{isUnknown} and -\code{unknownToNA} need not match the class of \code{x} (otherwise factor -should be used) as the test is internally done with \code{\%in\%}, which -nicely resolves coercing issues. - -<<ex07>>= -(xFac <- factor(c(0, "BA", "RA", "BA", NA, "NA"))) -isUnknown(x=xFac) -isUnknown(x=xFac, unknown=0) -isUnknown(x=xFac, unknown=c(0, NA)) -isUnknown(x=xFac, unknown=c(0, "NA")) -isUnknown(x=xFac, unknown=c(0, "NA", NA)) - -(xFac <- unknownToNA(x=xFac, unknown=0)) -(xFac <- NAToUnknown(x=xFac, unknown=0)) -@ - -These two examples with classes \code{numeric} and \code{factor} are fairly -simple and we could get the same results with one or two lines of \R{} -code. The real benefit of the set of functions presented here is in -\code{list} and \code{data.frame} methods, where \code{data.frame} methods -are merely wrappers for \code{list} methods. - -We need additional flexibility for \code{list}/\code{data.frame} methods, -due to possibly having multiple unknown values that can be different among -\code{list} components or \code{data.frame} columns. For these two methods, -the argument \code{unknown} can be either a \code{vector} or \code{list}, -both possibly named. Of course, greater flexibility (defining multiple -unknown values per component/column) can be achieved with a \code{list}. - -When a \code{vector}/\code{list} object passed to the argument -\code{unknown} is not named, the first value/component of a -\code{vector}/\code{list} matches the first component/column of a -\code{list}/\code{data.frame}. This can be quite error prone, especially -with \code{vectors}. Therefore, I encourage the use of a \code{list}. In -case \code{vector}/\code{list} passed to argument \code{unknown} is named, -names are matched to names of \code{list} or \code{data.frame}. If lengths -of \code{unknown} and \code{list} or \code{data.frame} do not match, -recycling occurs. - -The example below illustrates the application of the described functions to -a list which is composed of previously defined and modified numeric -(\code{xNum}) and factor (\code{xFac}) classes. First, function -\code{isUnknown} is used with \code{0} as an unknown value. Note that we -get \code{FALSE} for \code{NA}s as has been the case in the first example. - -<<ex08>>= -(xList <- list(a=xNum, b=xFac)) -isUnknown(x=xList, unknown=0) -@ - -We need to add \code{NA} as an unknown value. However, we do not get the -expected result this way! - -<<ex09>>= -isUnknown(x=xList, unknown=c(0, NA)) -@ - -This is due to matching of values in the argument \code{unknown} and -components in a \code{list}; i.e., \code{0} is used for component \code{a} -and \code{NA} for component \code{b}. Therefore, it is less error prone -and more flexible to pass a \code{list} (preferably a named list) to the -argument \code{unknown}, as shown below. - -<<ex10>>= -(xList1 <- unknownToNA(x=xList, - unknown=list(b=c(0, "NA"), - a=0))) -@ - -Changing \code{NA}s to some other value (only one per component/column) can -be accomplished as follows: - -<<ex11>>= -NAToUnknown(x=xList1, - unknown=list(b="no", a=0)) -@ - -A named component \code{.default} of a \code{list} passed to argument -\code{unknown} has a special meaning as it will match a component/column -with that name and any other not defined in \code{unknown}. As such it is -very useful if the number of components/columns with the same unknown -value(s) is large. Consider a wide \code{data.frame} named \code{df}. Now -\code{.default} can be used to define unknown value for several columns: - -<<ex12, echo=FALSE>>= -df <- data.frame(col1=c(0, 1, 999, 2), - col2=c("a", "b", "c", "unknown"), - col3=c(0, 1, 2, 3), - col4=c(0, 1, 2, 2)) -@ - -<<ex13>>= -tmp <- list(.default=0, - col1=999, - col2="unknown") -(df2 <- unknownToNA(x=df, - unknown=tmp)) -@ - -If there is a need to work only on some components/columns you can of -course ``skip'' columns with standard \R{} mechanisms, i.e., -by subsetting \code{list} or \code{data.frame} objects: - -<<ex14>>= -df2 <- df -cols <- c("col1", "col2") -tmp <- list(col1=999, - col2="unknown") -df2[, cols] <- unknownToNA(x=df[, cols], - unknown=tmp) -df2 -@ - -\section{Summary} - -Functions \code{isUnknown}, \code{unknownToNA} and \code{NAToUnknown} -provide a useful interface to work with various representations of -unknown/missing values. Their use is meant primarily for shaping the data -after importing to or before exporting from \R{}. I welcome any comments or -suggestions. - -% \bibliography{refs} - -\begin{thebibliography}{1} -\providecommand{\natexlab}[1]{#1} -\providecommand{\url}[1]{\texttt{#1}} -\expandafter\ifx\csname urlstyle\endcsname\relax - \providecommand{\doi}[1]{doi: #1}\else - \providecommand{\doi}{doi: \begingroup \urlstyle{rm}\Url}\fi - -\bibitem[Gorjanc(2007)]{Gorjanc} -G.~Gorjanc. -\newblock Working with unknown values: the gdata package. -\newblock \emph{R News}, 7\penalty0 (1):\penalty0 24--26, 2007. -\newblock URL \url{http://CRAN.R-project.org/doc/Rnews/Rnews_2007-1.pdf}. - -\bibitem[{R Development Core Team}(2006)]{RImportExportManual} -{R Development Core Team}. -\newblock \emph{R Data Import/Export}, 2006. -\newblock URL \url{http://cran.r-project.org/manuals.html}. -\newblock ISBN 3-900051-10-0. - -\bibitem[Warnes (2006)]{WarnesGdata} -G.~R. Warnes. -\newblock \emph{gdata: Various R programming tools for data manipulation}, - 2006. -\newblock URL - \url{http://cran.r-project.org/src/contrib/Descriptions/gdata.html}. -\newblock R package version 2.3.1. Includes R source code and/or documentation - contributed by Ben Bolker, Gregor Gorjanc and Thomas Lumley. - -\end{thebibliography} - -\address{Gregor Gorjanc\\ - University of Ljubljana, Slovenia\\ -\email{gre...@bf...}} - -\end{article} - -\end{document} Copied: trunk/gdata/vignettes/mapLevels.Rnw (from rev 1786, trunk/gdata/inst/doc/mapLevels.Rnw) =================================================================== --- trunk/gdata/vignettes/mapLevels.Rnw (rev 0) +++ trunk/gdata/vignettes/mapLevels.Rnw 2014-04-05 14:26:49 UTC (rev 1789) @@ -0,0 +1,229 @@ + +%\VignetteIndexEntry{Mapping levels of a factor} +%\VignettePackage{gdata} +%\VignetteKeywords{levels, factor, manip} + +\documentclass[a4paper]{report} +\usepackage{Rnews} +\usepackage[round]{natbib} +\bibliographystyle{abbrvnat} + +\usepackage{Sweave} +\SweaveOpts{strip.white=all, keep.source=TRUE} + +\begin{document} + +\begin{article} + +\title{Mapping levels of a factor} +\subtitle{The \pkg{gdata} package} +\author{by Gregor Gorjanc} + +\maketitle + +\section{Introduction} + +Factors use levels attribute to store information on mapping between +internal integer codes and character values i.e. levels. First level is +mapped to internal integer code 1 and so on. Although some users do not +like factors, their use is more efficient in terms of storage than for +character vectors. Additionally, there are many functions in base \R{} that +provide additional value for factors. Sometimes users need to work with +internal integer codes and mapping them back to factor, especially when +interfacing external programs. Mapping information is also of interest if +there are many factors that should have the same set of levels. This note +describes \code{mapLevels} function, which is an utility function for +mapping the levels of a factor in \pkg{gdata} \footnote{from version 2.3.1} +package \citep{WarnesGdata}. + +\section{Description with examples} + +Function \code{mapLevels()} is an (S3) generic function and works on +\code{factor} and \code{character} atomic classes. It also works on +\code{list} and \code{data.frame} objects with previously mentioned atomic +classes. Function \code{mapLevels} produces a so called ``map'' with names +and values. Names are levels, while values can be internal integer codes or +(possibly other) levels. This will be clarified later on. Class of this +``map'' is \code{levelsMap}, if \code{x} in \code{mapLevels()} was atomic +or \code{listLevelsMap} otherwise - for \code{list} and \code{data.frame} +classes. The following example shows the creation and printout of such a +``map''. + +<<ex01>>= +library(gdata) +(fac <- factor(c("B", "A", "Z", "D"))) +(map <- mapLevels(x=fac)) +@ + +If we have to work with internal integer codes, we can transform factor to +integer and still get ``back the original factor'' with ``map'' used as +argument in \code{mapLevels<-} function as shown bellow. \code{mapLevels<-} +is also an (S3) generic function and works on same classes as +\code{mapLevels} plus \code{integer} atomic class. + +<<ex02>>= +(int <- as.integer(fac)) +mapLevels(x=int) <- map +int +identical(fac, int) +@ + +Internally ``map'' (\code{levelsMap} class) is a \code{list} (see bellow), +but its print method unlists it for ease of inspection. ``Map'' from +example has all components of length 1. This is not mandatory as +\code{mapLevels<-} function is only a wrapper around workhorse function +\code{levels<-} and the later can accept \code{list} with components of +various lengths. + +<<ex03>>= +str(map) +@ + +Although not of primary importance, this ``map'' can also be used to remap +factor levels as shown bellow. Components ``later'' in the map take over +the ``previous'' ones. Since this is not optimal I would rather recommend +other approaches for ``remapping'' the levels of a \code{factor}, say +\code{recode} in \pkg{car} package \citep{FoxCar}. + +<<ex04>>= +map[[2]] <- as.integer(c(1, 2)) +map +int <- as.integer(fac) +mapLevels(x=int) <- map +int +@ + +Up to now examples showed ``map'' with internal integer codes for values +and levels for names. I call this integer ``map''. On the other hand +character ``map'' uses levels for values and (possibly other) levels for +names. This feature is a bit odd at first sight, but can be used to easily +unify levels and internal integer codes across several factors. Imagine +you have a factor that is for some reason split into two factors \code{f1} +and \code{f2} and that each factor does not have all levels. This is not +uncommon situation. + +<<ex05>>= +(f1 <- factor(c("A", "D", "C"))) +(f2 <- factor(c("B", "D", "C"))) +@ + +If we work with this factors, we need to be careful as they do not have the +same set of levels. This can be solved with appropriately specifying +\code{levels} argument in creation of factors i.e. \code{levels=c("A", "B", + "C", "D")} or with proper use of \code{levels<-} function. I say proper +as it is very tempting to use: + +<<ex06>>= +fTest <- f1 +levels(fTest) <- c("A", "B", "C", "D") +fTest +@ + +Above example extends set of levels, but also changes level of 2nd and 3rd +element in \code{fTest}! Proper use of \code{levels<-} (as shown in +\code{levels} help page) would be: + +<<ex07>>= +fTest <- f1 +levels(fTest) <- list(A="A", B="B", + C="C", D="D") +fTest +@ + +Function \code{mapLevels} with character ``map'' can help us in such +scenarios to unify levels and internal integer codes across several +factors. Again the workhorse under this process is \code{levels<-} function +from base \R{}! Function \code{mapLevels<-} just controls the assignment of +(integer or character) ``map'' to \code{x}. Levels in \code{x} that match +``map'' values (internal integer codes or levels) are changed to ``map'' +names (possibly other levels) as shown in \code{levels} help page. Levels +that do not match are converted to \code{NA}. Integer ``map'' can be +applied to \code{integer} or \code{factor}, while character ``map'' can be +applied to \code{character} or \code{factor}. Result of \code{mapLevels<-} +is always a \code{factor} with possibly ``remapped'' levels. + +To get one joint character ``map'' for several factors, we need to put +factors in a \code{list} or \code{data.frame} and use arguments +\code{codes=FALSE} and \code{combine=TRUE}. Such map can then be used to +unify levels and internal integer codes. + +<<ex08>>= +(bigMap <- mapLevels(x=list(f1, f2), + codes=FALSE, + combine=TRUE)) +mapLevels(f1) <- bigMap +mapLevels(f2) <- bigMap +f1 +f2 +cbind(as.character(f1), as.integer(f1), + as.character(f2), as.integer(f2)) +@ + +If we do not specify \code{combine=TRUE} (which is the default behaviour) +and \code{x} is a \code{list} or \code{data.frame}, \code{mapLevels} +returns ``map'' of class \code{listLevelsMap}. This is internally a +\code{list} of ``maps'' (\code{levelsMap} objects). Both +\code{listLevelsMap} and \code{levelsMap} objects can be passed to +\code{mapLevels<-} for \code{list}/\code{data.frame}. Recycling occurs when +length of \code{listLevelsMap} is not the same as number of +components/columns of a \code{list}/\code{data.frame}. + +Additional convenience methods are also implemented to ease the work with +``maps'': + +\begin{itemize} + +\item \code{is.levelsMap}, \code{is.listLevelsMap}, \code{as.levelsMap} and + \code{as.listLevelsMap} for testing and coercion of user defined + ``maps'', + +\item \code{"["} for subsetting, + +\item \code{c} for combining \code{levelsMap} or \code{listLevelsMap} + objects; argument \code{recursive=TRUE} can be used to coerce + \code{listLevelsMap} to \code{levelsMap}, for example \code{c(llm1, llm2, + recursive=TRUE)} and + +\item \code{unique} and \code{sort} for \code{levelsMap}. + +\end{itemize} + +\section{Summary} + +Functions \code{mapLevels} and \code{mapLevels<-} can help users to map +internal integer codes to factor levels and unify levels as well as +internal integer codes among several factors. I welcome any comments or +suggestions. + +% \bibliography{refs} +\begin{thebibliography}{1} +\providecommand{\natexlab}[1]{#1} +\providecommand{\url}[1]{\texttt{#1}} +\expandafter\ifx\csname urlstyle\endcsname\relax + \providecommand{\doi}[1]{doi: #1}\else + \providecommand{\doi}{doi: \begingroup \urlstyle{rm}\Url}\fi + +\bibitem[Fox(2006)]{FoxCar} +J.~Fox. +\newblock \emph{car: Companion to Applied Regression}, 2006. +\newblock URL \url{http://socserv.socsci.mcmaster.ca/jfox/}. +\newblock R package version 1.1-1. + +\bibitem[Warnes(2006)]{WarnesGdata} +G.~R. Warnes. +\newblock \emph{gdata: Various R programming tools for data manipulation}, + 2006. +\newblock URL + \url{http://cran.r-project.org/src/contrib/Descriptions/gdata.html}. +\newblock R package version 2.3.1. Includes R source code and/or documentation + contributed by Ben Bolker, Gregor Gorjanc and Thomas Lumley. + +\end{thebibliography} + +\address{Gregor Gorjanc\\ + University of Ljubljana, Slovenia\\ +\email{gre...@bf...}} + +\end{article} + +\end{document} Copied: trunk/gdata/vignettes/unknown.Rnw (from rev 1786, trunk/gdata/inst/doc/unknown.Rnw) =================================================================== --- trunk/gdata/vignettes/unknown.Rnw (rev 0) +++ trunk/gdata/vignettes/unknown.Rnw 2014-04-05 14:26:49 UTC (rev 1789) @@ -0,0 +1,272 @@ + +%\VignetteIndexEntry{Working with Unknown Values} +%\VignettePackage{gdata} +%\VignetteKeywords{unknown, missing, manip} + +\documentclass[a4paper]{report} +\usepackage{Rnews} +\usepackage[round]{natbib} +\bibliographystyle{abbrvnat} + +\usepackage{Sweave} +\SweaveOpts{strip.white=all, keep.source=TRUE} + +\begin{document} + +\begin{article} + +\title{Working with Unknown Values} +\subtitle{The \pkg{gdata} package} +\author{by Gregor Gorjanc} + +\maketitle + +This vignette has been published as \cite{Gorjanc}. + +\section{Introduction} + +Unknown or missing values can be represented in various ways. For example +SAS uses \code{.}~(dot), while \R{} uses \code{NA}, which we can read as +Not Available. When we import data into \R{}, say via \code{read.table} or +its derivatives, conversion of blank fields to \code{NA} (according to +\code{read.table} help) is done for \code{logical}, \code{integer}, +\code{numeric} and \code{complex} classes. Additionally, the +\code{na.strings} argument can be used to specify values that should also +be converted to \code{NA}. Inversely, there is an argument \code{na} in +\code{write.table} and its derivatives to define value that will replace +\code{NA} in exported data. There are also other ways to import/export data +into \R{} as described in the {\emph R Data Import/Export} manual +\citep{RImportExportManual}. However, all approaches lack the possibility +to define unknown value(s) for some particular column. It is possible that +an unknown value in one column is a valid value in another column. For +example, I have seen many datasets where values such as 0, -9, 999 and +specific dates are used as column specific unknown values. + +This note describes a set of functions in package \pkg{gdata}\footnote{ + package version 2.3.1} \citep{WarnesGdata}: \code{isUnknown}, +\code{unknownToNA} and \code{NAToUnknown}, which can help with testing for +unknown values and conversions between unknown values and \code{NA}. All +three functions are generic (S3) and were tested (at the time of writing) +to work with: \code{integer}, \code{numeric}, \code{character}, +\code{factor}, \code{Date}, \code{POSIXct}, \code{POSIXlt}, \code{list}, +\code{data.frame} and \code{matrix} classes. + +\section{Description with examples} + +The following examples show simple usage of these functions on +\code{numeric} and \code{factor} classes, where value \code{0} (beside +\code{NA}) should be treated as an unknown value: + +<<ex01>>= +library("gdata") +xNum <- c(0, 6, 0, 7, 8, 9, NA) +isUnknown(x=xNum) +@ + +The default unknown value in \code{isUnknown} is \code{NA}, which means +that output is the same as \code{is.na} --- at least for atomic +classes. However, we can pass the argument \code{unknown} to define which +values should be treated as unknown: + +<<ex02>>= +isUnknown(x=xNum, unknown=0) +@ + +This skipped \code{NA}, but we can get the expected answer after +appropriately adding \code{NA} into the argument \code{unknown}: + +<<ex03>>= +isUnknown(x=xNum, unknown=c(0, NA)) +@ + +Now, we can change all unknown values to \code{NA} with \code{unknownToNA}. +There is clearly no need to add \code{NA} here. This step is very handy +after importing data from an external source, where many different unknown +values might be used. Argument \code{warning=TRUE} can be used, if there is +a need to be warned about ``original'' \code{NA}s: + +<<ex04>>= +(xNum2 <- unknownToNA(x=xNum, unknown=0)) +@ + +Prior to export from \R{}, we might want to change unknown values +(\code{NA} in \R{}) to some other value. Function \code{NAToUnknown} can be +used for this: + +<<ex05>>= +NAToUnknown(x=xNum2, unknown=999) +@ + +Converting \code{NA} to a value that already exists in \code{x} issues an +error, but \code{force=TRUE} can be used to overcome this if needed. But be +warned that there is no way back from this step: + +<<ex06>>= +NAToUnknown(x=xNum2, unknown=7, force=TRUE) +@ + +Examples below show all peculiarities with class \code{factor}. +\code{unknownToNA} removes \code{unknown} value from levels and inversely +\code{NAToUnknown} adds it with a warning. Additionally, \code{"NA"} is +properly distinguished from \code{NA}. It can also be seen that the +argument \code{unknown} in functions \code{isUnknown} and +\code{unknownToNA} need not match the class of \code{x} (otherwise factor +should be used) as the test is internally done with \code{\%in\%}, which +nicely resolves coercing issues. + +<<ex07>>= +(xFac <- factor(c(0, "BA", "RA", "BA", NA, "NA"))) +isUnknown(x=xFac) +isUnknown(x=xFac, unknown=0) +isUnknown(x=xFac, unknown=c(0, NA)) +isUnknown(x=xFac, unknown=c(0, "NA")) +isUnknown(x=xFac, unknown=c(0, "NA", NA)) + +(xFac <- unknownToNA(x=xFac, unknown=0)) +(xFac <- NAToUnknown(x=xFac, unknown=0)) +@ + +These two examples with classes \code{numeric} and \code{factor} are fairly +simple and we could get the same results with one or two lines of \R{} +code. The real benefit of the set of functions presented here is in +\code{list} and \code{data.frame} methods, where \code{data.frame} methods +are merely wrappers for \code{list} methods. + +We need additional flexibility for \code{list}/\code{data.frame} methods, +due to possibly having multiple unknown values that can be different among +\code{list} components or \code{data.frame} columns. For these two methods, +the argument \code{unknown} can be either a \code{vector} or \code{list}, +both possibly named. Of course, greater flexibility (defining multiple +unknown values per component/column) can be achieved with a \code{list}. + +When a \code{vector}/\code{list} object passed to the argument +\code{unknown} is not named, the first value/component of a +\code{vector}/\code{list} matches the first component/column of a +\code{list}/\code{data.frame}. This can be quite error prone, especially +with \code{vectors}. Therefore, I encourage the use of a \code{list}. In +case \code{vector}/\code{list} passed to argument \code{unknown} is named, +names are matched to names of \code{list} or \code{data.frame}. If lengths +of \code{unknown} and \code{list} or \code{data.frame} do not match, +recycling occurs. + +The example below illustrates the application of the described functions to +a list which is composed of previously defined and modified numeric +(\code{xNum}) and factor (\code{xFac}) classes. First, function +\code{isUnknown} is used with \code{0} as an unknown value. Note that we +get \code{FALSE} for \code{NA}s as has been the case in the first example. + +<<ex08>>= +(xList <- list(a=xNum, b=xFac)) +isUnknown(x=xList, unknown=0) +@ + +We need to add \code{NA} as an unknown value. However, we do not get the +expected result this way! + +<<ex09>>= +isUnknown(x=xList, unknown=c(0, NA)) +@ + +This is due to matching of values in the argument \code{unknown} and +components in a \code{list}; i.e., \code{0} is used for component \code{a} +and \code{NA} for component \code{b}. Therefore, it is less error prone +and more flexible to pass a \code{list} (preferably a named list) to the +argument \code{unknown}, as shown below. + +<<ex10>>= +(xList1 <- unknownToNA(x=xList, + unknown=list(b=c(0, "NA"), + a=0))) +@ + +Changing \code{NA}s to some other value (only one per component/column) can +be accomplished as follows: + +<<ex11>>= +NAToUnknown(x=xList1, + unknown=list(b="no", a=0)) +@ + +A named component \code{.default} of a \code{list} passed to argument +\code{unknown} has a special meaning as it will match a component/column +with that name and any other not defined in \code{unknown}. As such it is +very useful if the number of components/columns with the same unknown +value(s) is large. Consider a wide \code{data.frame} named \code{df}. Now +\code{.default} can be used to define unknown value for several columns: + +<<ex12, echo=FALSE>>= +df <- data.frame(col1=c(0, 1, 999, 2), + col2=c("a", "b", "c", "unknown"), + col3=c(0, 1, 2, 3), + col4=c(0, 1, 2, 2)) +@ + +<<ex13>>= +tmp <- list(.default=0, + col1=999, + col2="unknown") +(df2 <- unknownToNA(x=df, + unknown=tmp)) +@ + +If there is a need to work only on some components/columns you can of +course ``skip'' columns with standard \R{} mechanisms, i.e., +by subsetting \code{list} or \code{data.frame} objects: + +<<ex14>>= +df2 <- df +cols <- c("col1", "col2") +tmp <- list(col1=999, + col2="unknown") +df2[, cols] <- unknownToNA(x=df[, cols], + unknown=tmp) +df2 +@ + +\section{Summary} + +Functions \code{isUnknown}, \code{unknownToNA} and \code{NAToUnknown} +provide a useful interface to work with various representations of +unknown/missing values. Their use is meant primarily for shaping the data +after importing to or before exporting from \R{}. I welcome any comments or +suggestions. + +% \bibliography{refs} + +\begin{thebibliography}{1} +\providecommand{\natexlab}[1]{#1} +\providecommand{\url}[1]{\texttt{#1}} +\expandafter\ifx\csname urlstyle\endcsname\relax + \providecommand{\doi}[1]{doi: #1}\else + \providecommand{\doi}{doi: \begingroup \urlstyle{rm}\Url}\fi + +\bibitem[Gorjanc(2007)]{Gorjanc} +G.~Gorjanc. +\newblock Working with unknown values: the gdata package. +\newblock \emph{R News}, 7\penalty0 (1):\penalty0 24--26, 2007. +\newblock URL \url{http://CRAN.R-project.org/doc/Rnews/Rnews_2007-1.pdf}. + +\bibitem[{R Development Core Team}(2006)]{RImportExportManual} +{R Development Core Team}. +\newblock \emph{R Data Import/Export}, 2006. +\newblock URL \url{http://cran.r-project.org/manuals.html}. +\newblock ISBN 3-900051-10-0. + +\bibitem[Warnes (2006)]{WarnesGdata} +G.~R. Warnes. +\newblock \emph{gdata: Various R programming tools for data manipulation}, + 2006. +\newblock URL + \url{http://cran.r-project.org/src/contrib/Descriptions/gdata.html}. +\newblock R package version 2.3.1. Includes R source code and/or documentation + contributed by Ben Bolker, Gregor Gorjanc and Thomas Lumley. + +\end{thebibliography} + +\address{Gregor Gorjanc\\ + University of Ljubljana, Slovenia\\ +\email{gre...@bf...}} + +\end{article} + +\end{document} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 13:57:14
|
Revision: 1788 http://sourceforge.net/p/r-gregmisc/code/1788 Author: warnes Date: 2014-04-05 13:57:10 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Change 'aggregate.table' from deprecated to defunct. Modified Paths: -------------- trunk/gdata/R/aggregate.table.R Added Paths: ----------- trunk/gdata/man/gdata-defunct.Rd Removed Paths: ------------- trunk/gdata/man/aggregate.table.Rd Modified: trunk/gdata/R/aggregate.table.R =================================================================== --- trunk/gdata/R/aggregate.table.R 2014-04-05 12:53:38 UTC (rev 1787) +++ trunk/gdata/R/aggregate.table.R 2014-04-05 13:57:10 UTC (rev 1788) @@ -2,32 +2,34 @@ aggregate.table <- function(x, by1, by2, FUN=mean, ...) { - warning("'aggregate.table' is deprecated and will be removed in a future version of the gdata package. ", - "Please use 'tapply(X=", - deparse(substitute(x)), - ", INDEX=list(", - deparse(substitute(by1)), - ", ", - deparse(substitute(by2)), - "), FUN=", - deparse(substitute(FUN)), - if(length(list(...))>0) - { - l <- list(...) - paste(", ", - paste(names(l),"=", - deparse(substitute(...)), - sep="", - collapse=", ") - ) - }, - ")' instead.") - tapply(X=x, INDEX=list(by1, by2), FUN=FUN, ...) + .Defunct( + new=paste( + "tapply(X=", + deparse(substitute(x)), + ", INDEX=list(", + deparse(substitute(by1)), + ", ", + deparse(substitute(by2)), + "), FUN=", + deparse(substitute(FUN)), + if(length(list(...))>0) + { + l <- list(...) + paste(", ", + paste(names(l),"=", + deparse(substitute(...)), + sep="", + collapse=", ") + ) + }, + ")", sep=""), + package="gdata" + ) } ## aggregate.table <- function(x, by1, by2, FUN=mean, ... ) ## { -## +## ## tab <- matrix( nrow=nlevels(by1), ncol=nlevels(by2) ) ## dimnames(tab) <- list(levels(by1),levels(by2)) ## Deleted: trunk/gdata/man/aggregate.table.Rd =================================================================== --- trunk/gdata/man/aggregate.table.Rd 2014-04-05 12:53:38 UTC (rev 1787) +++ trunk/gdata/man/aggregate.table.Rd 2014-04-05 13:57:10 UTC (rev 1788) @@ -1,94 +0,0 @@ -% $Id$ -% -% $Log$ -% Revision 1.7 2005/09/12 15:42:45 nj7w -% Updated Greg's email -% -% Revision 1.6 2005/06/09 14:20:25 nj7w -% Updating the version number, and various help files to synchronize splitting of gregmisc bundle in 4 individual components. -% -% Revision 1.1.1.1 2005/05/25 22:07:33 nj7w -% Initial entry for individual package gdata -% -% Revision 1.5 2003/11/17 22:09:00 warnes -% Fix syntax error. -% -% Revision 1.4 2003/06/07 17:58:37 warnes -% -% - Fixed error in examples. Had sqrt(var(x)/(n-1)) for the standard -% error of the mean instead of sqrt(var(x)/n). -% -% Revision 1.3 2002/09/23 13:59:30 warnes -% - Modified all files to include CVS Id and Log tags. -% -% - -\name{aggregate.table} -\alias{aggregate.table} -\title{Create 2-Way Table of Summary Statistics} -\description{ - Splits the data into subsets based on two factors, computes a summary - statistic on each subset, and arranges the results in a 2-way table. -} -\usage{ -aggregate.table(x, by1, by2, FUN=mean, ...) -} -%- maybe also `usage' for other objects documented here. -\arguments{ - \item{x}{ data to be summarized } - \item{by1}{ first grouping factor. } - \item{by2}{ second grouping factor. } - \item{FUN}{ a scalar function to compute the summary statistics which can - be applied to all data subsets. Defaults to \code{mean}.} - \item{\dots}{ Optional arguments for \code{FUN}. } -} -%\details{ -% ~~ If necessary, more details than the __description__ above ~~ -%} -\value{ - Returns a matrix with one element for each combination of \code{by1} - and \code{by2}. -} -\author{ Gregory R. Warnes \email{gr...@wa...}} - -\seealso{ \code{\link{aggregate}}, \code{\link{tapply}}, - \code{\link{interleave}} } -\note{This function is DEPRECIATED. Please use \code{tapply} - instead. See example for illustration.} -\examples{ -# Useful example: -# -# Create a 2-way table of means, standard errors, and # obs -set.seed(314159) -g1 <- sample(letters[1:5], 1000, replace=TRUE) -g2 <- sample(LETTERS[1:3], 1000, replace=TRUE ) -dat <- rnorm(1000) - -stderr <- function(x) sqrt( var(x,na.rm=TRUE) / nobs(x) ) - -## Depreciated: -means <- aggregate.table( dat, g1, g2, mean ) -## Instead use: -means <- tapply( dat, list(g1, g2), mean ) - -## Depreciated -stderrs <- aggregate.table( dat, g1, g2, stderr ) -## Instead use: -stderrs <- tapply( dat, list(g1, g2), stderr ) - -## Depreciated -ns <- aggregate.table( dat, g1, g2, nobs ) -## Instead use: -ns <- tapply( dat, list(g1, g2), nobs ) - -blanks <- matrix( " ", nrow=5, ncol=3) - -tab <- interleave( "Mean"=round(means,2), - "Std Err"=round(stderrs,2), - "N"=ns, " " = blanks, sep=" " ) - -print(tab, quote=FALSE) -} -\keyword{iteration} -\keyword{category} - Copied: trunk/gdata/man/gdata-defunct.Rd (from rev 1786, trunk/gdata/man/aggregate.table.Rd) =================================================================== --- trunk/gdata/man/gdata-defunct.Rd (rev 0) +++ trunk/gdata/man/gdata-defunct.Rd 2014-04-05 13:57:10 UTC (rev 1788) @@ -0,0 +1,24 @@ +\name{gdata-defunct} +\alias{aggregate.table} +\title{Defunct Functions in Package 'gdata'} +\description{ + The functions or variables listed here are no longer part of 'gdata'. +} +\usage{ +aggregate.table(x, by1, by2, FUN=mean, ...) +} +%- maybe also `usage' for other objects documented here. +\arguments{ + \item{x}{ data to be summarized } + \item{by1}{ first grouping factor. } + \item{by2}{ second grouping factor. } + \item{FUN}{ a scalar function to compute the summary statistics which can + be applied to all data subsets. Defaults to \code{mean}.} + \item{\dots}{ Optional arguments for \code{FUN}. } +} +\details{ + \code{aggregate.table(x, by1, by2, FUN=mean, ...)} should be replacede + by \code{tapply(X=x, INDEX=list(by1, by2), FUN=FUN, ...)}. +} + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 12:53:41
|
Revision: 1787 http://sourceforge.net/p/r-gregmisc/code/1787 Author: warnes Date: 2014-04-05 12:53:38 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Complete changes so that the unit tests are run as part of R CMD check Modified Paths: -------------- trunk/gdata/DESCRIPTION trunk/gdata/man/gdata-package.Rd trunk/gdata/tests/runRUnitTests.R Added Paths: ----------- trunk/gdata/tests/unitTests/ Removed Paths: ------------- trunk/gdata/inst/unitTests/ Modified: trunk/gdata/DESCRIPTION =================================================================== --- trunk/gdata/DESCRIPTION 2014-04-05 02:25:54 UTC (rev 1786) +++ trunk/gdata/DESCRIPTION 2014-04-05 12:53:38 UTC (rev 1787) @@ -12,4 +12,4 @@ Maintainer: Gregory R. Warnes <gr...@wa...> License: GPL-2 NeedsCompilation: no -Depends: RUnit +Recommends: RUnit Modified: trunk/gdata/man/gdata-package.Rd =================================================================== --- trunk/gdata/man/gdata-package.Rd 2014-04-05 02:25:54 UTC (rev 1786) +++ trunk/gdata/man/gdata-package.Rd 2014-04-05 12:53:38 UTC (rev 1787) @@ -32,13 +32,4 @@ } -\section{Testing}{ - -If you want to perform the validity/unit testing of the installed -\pkg{ggmisc} package on your own computer, take a look at -\code{\link{.runRUnitTestsGdata}} function - please note that -you need the \pkg{RUnit} package for this to work. - -} - \keyword{package} \ No newline at end of file Modified: trunk/gdata/tests/runRUnitTests.R =================================================================== --- trunk/gdata/tests/runRUnitTests.R 2014-04-05 02:25:54 UTC (rev 1786) +++ trunk/gdata/tests/runRUnitTests.R 2014-04-05 12:53:38 UTC (rev 1787) @@ -39,9 +39,10 @@ if(require("RUnit", quietly=TRUE)) { - pkg <- c(read.dcf(file="../DESCRIPTION", fields="Package")) - path <- normalizePath( file.path(getwd(), "..", "inst", "unitTests") ) + pkg <- 'gdata' + path <- normalizePath("unitTests") + cat("\nRunning unit tests\n") print(list(pkg=pkg, getwd=getwd(), pathToUnitTests=path)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 02:25:57
|
Revision: 1786 http://sourceforge.net/p/r-gregmisc/code/1786 Author: warnes Date: 2014-04-05 02:25:54 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Update NEWS for gdata 2.13.4 Modified Paths: -------------- trunk/gdata/DESCRIPTION trunk/gdata/inst/NEWS Modified: trunk/gdata/DESCRIPTION =================================================================== --- trunk/gdata/DESCRIPTION 2014-04-05 02:25:02 UTC (rev 1785) +++ trunk/gdata/DESCRIPTION 2014-04-05 02:25:54 UTC (rev 1786) @@ -4,11 +4,12 @@ Depends: R (>= 2.13.0) SystemRequirements: perl Imports: gtools -Version: 2.13.2 -Date: 2013-06-28 +Version: 2.13.3 +Date: 2014-04-04 Author: Gregory R. Warnes, Ben Bolker, Gregor Gorjanc, Gabor Grothendieck, Ales Korosec, Thomas Lumley, Don MacQueen, Arni Magnusson, Jim Rogers, and others Maintainer: Gregory R. Warnes <gr...@wa...> License: GPL-2 NeedsCompilation: no +Depends: RUnit Modified: trunk/gdata/inst/NEWS =================================================================== --- trunk/gdata/inst/NEWS 2014-04-05 02:25:02 UTC (rev 1785) +++ trunk/gdata/inst/NEWS 2014-04-05 02:25:54 UTC (rev 1786) @@ -1,3 +1,16 @@ +Changes in 2.13.3 (2014-04-04) +------------------------------ + +Bug Fixes + +- Unit tests were incorrectly checking for equality of optional POSIXlt + components. (Bug reported by Brian Ripley). + +Other Changes + +- Unit tests now follow R standard practice + + Changes in 2.13.2 (2013-06-28) ------------------------------ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 02:25:04
|
Revision: 1785 http://sourceforge.net/p/r-gregmisc/code/1785 Author: warnes Date: 2014-04-05 02:25:02 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Update NAMESPACE file to remove deleted function Modified Paths: -------------- trunk/gdata/NAMESPACE Modified: trunk/gdata/NAMESPACE =================================================================== --- trunk/gdata/NAMESPACE 2014-04-05 02:23:45 UTC (rev 1784) +++ trunk/gdata/NAMESPACE 2014-04-05 02:25:02 UTC (rev 1785) @@ -43,7 +43,7 @@ write.fwf, xls2csv, xls2tab, - xls2tsv, + xls2tsv, xls2sep, xlsFormats, @@ -57,10 +57,7 @@ mapLevels, as.levelsMap, as.listLevelsMap, is.levelsMap, is.listLevelsMap, "mapLevels<-", ## unknown stuff - isUnknown, unknownToNA, NAToUnknown, - - ## Unit testing - .runRUnitTestsGdata + isUnknown, unknownToNA, NAToUnknown ) importFrom(stats, reorder) @@ -124,7 +121,7 @@ ## nobs stuff S3method(nobs, data.frame) -S3method(nobs, default) +S3method(nobs, default) S3method(nobs, lm) # now provided by stats package ## Object size stuff This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 02:23:50
|
Revision: 1784 http://sourceforge.net/p/r-gregmisc/code/1784 Author: warnes Date: 2014-04-05 02:23:45 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Move unit test files back to inst/unitTests. Fix up runRUnitTests.R to work properly in the new location Modified Paths: -------------- trunk/gdata/tests/runRUnitTests.R Added Paths: ----------- trunk/gdata/inst/unitTests/Makefile trunk/gdata/inst/unitTests/runit.bindData.R trunk/gdata/inst/unitTests/runit.cbindX.R trunk/gdata/inst/unitTests/runit.drop.levels.R trunk/gdata/inst/unitTests/runit.getDateTimeParts.R trunk/gdata/inst/unitTests/runit.mapLevels.R trunk/gdata/inst/unitTests/runit.nPairs.R trunk/gdata/inst/unitTests/runit.reorder.factor.R trunk/gdata/inst/unitTests/runit.trim.R trunk/gdata/inst/unitTests/runit.trimSum.R trunk/gdata/inst/unitTests/runit.unknown.R trunk/gdata/inst/unitTests/runit.wideByFactor.R trunk/gdata/inst/unitTests/runit.write.fwf.R Removed Paths: ------------- trunk/gdata/tests/Makefile trunk/gdata/tests/runit.bindData.R trunk/gdata/tests/runit.cbindX.R trunk/gdata/tests/runit.drop.levels.R trunk/gdata/tests/runit.getDateTimeParts.R trunk/gdata/tests/runit.mapLevels.R trunk/gdata/tests/runit.nPairs.R trunk/gdata/tests/runit.reorder.factor.R trunk/gdata/tests/runit.trim.R trunk/gdata/tests/runit.trimSum.R trunk/gdata/tests/runit.unknown.R trunk/gdata/tests/runit.wideByFactor.R trunk/gdata/tests/runit.write.fwf.R Copied: trunk/gdata/inst/unitTests/Makefile (from rev 1782, trunk/gdata/tests/Makefile) =================================================================== --- trunk/gdata/inst/unitTests/Makefile (rev 0) +++ trunk/gdata/inst/unitTests/Makefile 2014-04-05 02:23:45 UTC (rev 1784) @@ -0,0 +1,18 @@ +TOP=../.. +PKG=${shell cd ${TOP};pwd} +SUITE=runRUnitTests.R +R=R + +test: # Run unit tests + ${R} --vanilla --slave < ${SUITE} + +all: inst test + +echo: # Echo env. variables + @echo "Package folder: ${PKG}" + @echo "R binary: ${R}" + +help: # Help + @echo -e '\nTarget: Dependency # Description'; \ + echo '=================================================='; \ + egrep '^[[:alnum:].+_()%]*:' ./Makefile Copied: trunk/gdata/inst/unitTests/runit.bindData.R (from rev 1782, trunk/gdata/tests/runit.bindData.R) =================================================================== --- trunk/gdata/inst/unitTests/runit.bindData.R (rev 0) +++ trunk/gdata/inst/unitTests/runit.bindData.R 2014-04-05 02:23:45 UTC (rev 1784) @@ -0,0 +1,75 @@ +### runit.bindData.R +###------------------------------------------------------------------------ +### What: Bind two data frames - unit tests +### $Id$ +### Time-stamp: <2008-12-30 11:58:50 ggorjan> +###------------------------------------------------------------------------ + +### {{{ --- Test setup --- + +if(FALSE) { + library("RUnit") + library("gdata") +} + +### }}} +### {{{ --- bindData --- + +test.bindData <- function() +{ + ## 'x'/'y' must be a data.frame + checkException(bindData(x=1:10, y=1:10)) + checkException(bindData(x=matrix(1:10), y=matrix(1:10))) + + n1 <- 6; n2 <- 12; n3 <- 4 + ## Single trait 1 + num <- c(5:n1, 10:13) + tmp1 <- data.frame(y1=rnorm(n=n1), + f1=factor(rep(c("A", "B"), n1/2)), + ch=letters[num], + fa=factor(letters[num]), + nu=(num) + 0.5, + id=factor(num), stringsAsFactors=FALSE) + + ## Single trait 2 with repeated records, some subjects also in tmp1 + num <- 4:9 + tmp2 <- data.frame(y2=rnorm(n=n2), + f2=factor(rep(c("C", "D"), n2/2)), + ch=letters[rep(num, times=2)], + fa=factor(letters[rep(c(num), times=2)]), + nu=c((num) + 0.5, (num) + 0.25), + id=factor(rep(num, times=2)), stringsAsFactors=FALSE) + + ## Single trait 3 with completely distinct set of subjects + num <- 1:4 + tmp3 <- data.frame(y3=rnorm(n=n3), + f3=factor(rep(c("E", "F"), n3/2)), + ch=letters[num], + fa=factor(letters[num]), + nu=(num) + 0.5, + id=factor(num), stringsAsFactors=FALSE) + + ## Combine all datasets + tmp12 <- bindData(x=tmp1, y=tmp2, common=c("id", "nu", "ch", "fa")) + tmp123 <- bindData(x=tmp12, y=tmp3, common=c("id", "nu", "ch", "fa")) + + checkEquals(names(tmp123), c("id", "nu", "ch", "fa", "y1", "f1", "y2", "f2", "y3", "f3")) + checkEquals(rbind(tmp1["id"], tmp2["id"], tmp3["id"]), tmp123["id"]) + checkEquals(rbind(tmp1["fa"], tmp2["fa"], tmp3["fa"]), tmp123["fa"]) + checkEquals(is.na(tmp123$y1), c(rep(FALSE, times=n1), rep(TRUE, times=n2+n3))) + checkEquals(is.na(tmp123$f1), c(rep(FALSE, times=n1), rep(TRUE, times=n2+n3))) + checkEquals(is.na(tmp123$y2), c(rep(TRUE, times=n1), rep(FALSE, times=n2), rep(TRUE, times=n3))) + checkEquals(is.na(tmp123$f2), c(rep(TRUE, times=n1), rep(FALSE, times=n2), rep(TRUE, times=n3))) + checkEquals(is.na(tmp123$y3), c(rep(TRUE, times=n1+n2), rep(FALSE, times=n3))) + checkEquals(is.na(tmp123$f3), c(rep(TRUE, times=n1+n2), rep(FALSE, times=n3))) +} + +### }}} +### {{{ Dear Emacs +## Local variables: +## folded-file: t +## End: +### }}} + +###------------------------------------------------------------------------ +### runit.bindData.R ends here Copied: trunk/gdata/inst/unitTests/runit.cbindX.R (from rev 1782, trunk/gdata/tests/runit.cbindX.R) =================================================================== --- trunk/gdata/inst/unitTests/runit.cbindX.R (rev 0) +++ trunk/gdata/inst/unitTests/runit.cbindX.R 2014-04-05 02:23:45 UTC (rev 1784) @@ -0,0 +1,81 @@ +### runit.cbindX.R +###------------------------------------------------------------------------ +### What: Unit tests for cbindX +### $Id:$ +### Time-stamp: <2008-08-05 13:40:49 ggorjan> +###------------------------------------------------------------------------ + +### {{{ --- Test setup --- + +if(FALSE) { + library("RUnit") + library("gdata") +} + +### }}} +### {{{ --- cbindX --- + +test.cbindX <- function() +{ + df1 <- data.frame(a=1:3, b=c("A", "B", "C")) + df2 <- data.frame(c=as.character(1:5), a=5:1) + + ma1 <- matrix(as.character(1:4), nrow=2, ncol=2) + ma2 <- matrix(1:6, nrow=3, ncol=2) + + df12test <- cbindX(df1, df2) + df12stand <- data.frame(a=c(1:3, NA, NA), + b=c("A", "B", "C", NA, NA), + c=as.character(1:5), + a=5:1) + names(df12stand)[4] <- "a" + checkEquals(df12test, df12stand) + + ma12test <- cbindX(ma1, ma2) + ma12stand <- matrix(as.character(c(1, 3, 1, 4, + 2, 4, 2, 5, + NA, NA, 3, 6)), nrow=3, ncol=4, byrow=TRUE) + checkEquals(ma12test, ma12stand) + + da11test <- cbindX(df1, ma1) + da11stand <- data.frame(a=1:3, + b=c("A", "B", "C"), + as.character(c(1:2, NA)), + as.character(c(3:4, NA))) + names(da11stand)[3:4] <- c("1", "2") + checkEquals(da11test, da11stand) + + tmpTest <- cbindX(df1, df2, ma1, ma2) + tmpStand <- data.frame(a=c(1:3, NA, NA), + b=c("A", "B", "C", NA, NA), + c=as.character(1:5), + a=5:1, + as.character(c(1:2, NA, NA, NA)), + as.character(c(3:4, NA, NA, NA)), + c(1:3, NA, NA), + c(4:6, NA, NA)) + names(tmpStand)[4:8] <- c("a", "1", "2", "1", "2") + checkEquals(tmpTest, tmpStand) + + tmpTest <- cbindX(ma1, ma2, df1, df2) + tmpStand <- data.frame(as.character(c(1:2, NA, NA, NA)), + as.character(c(3:4, NA, NA, NA)), + as.character(c(1:3, NA, NA)), + as.character(c(4:6, NA, NA)), + a=c(1:3, NA, NA), + b=c("A", "B", "C", NA, NA), + c=as.character(1:5), + a=5:1) + names(tmpStand)[c(1:4, 8)] <- c("1", "2", "3", "4", "a") + checkEquals(tmpTest, tmpStand) +} + +### }}} +### {{{ Dear Emacs +### Local variables: +### folded-file: t +### end: +### }}} + +###------------------------------------------------------------------------ +### runit.cbindX.R ends here Copied: trunk/gdata/inst/unitTests/runit.drop.levels.R (from rev 1782, trunk/gdata/tests/runit.drop.levels.R) =================================================================== --- trunk/gdata/inst/unitTests/runit.drop.levels.R (rev 0) +++ trunk/gdata/inst/unitTests/runit.drop.levels.R 2014-04-05 02:23:45 UTC (rev 1784) @@ -0,0 +1,42 @@ +### runit.drop.levels.R +###------------------------------------------------------------------------ +### What: Tests for drop.levels +### $Id$ +### Time-stamp: <2006-08-29 14:21:12 ggorjan> +###------------------------------------------------------------------------ + +### {{{ --- Test setup --- + +if(FALSE) { + library("RUnit") + library("gdata") +} + +### }}} +### {{{ --- drop.levels --- + +test.drop.levels <- function() +{ + f <- factor(c("A", "B", "C", "D"))[1:3] + fDrop <- factor(c("A", "B", "C")) + + l <- list(f=f, i=1:3, c=c("A", "B", "D")) + lDrop <- list(f=fDrop, i=1:3, c=c("A", "B", "D")) + + df <- as.data.frame(l) + dfDrop <- as.data.frame(lDrop) + + checkIdentical(drop.levels(f), fDrop) + checkIdentical(drop.levels(l), lDrop) + checkIdentical(drop.levels(df), dfDrop) +} + +### }}} +### {{{ Dear Emacs +## Local variables: +## folded-file: t +## End: +### }}} + +###------------------------------------------------------------------------ +### runit.drop.levels.R ends here Copied: trunk/gdata/inst/unitTests/runit.getDateTimeParts.R (from rev 1782, trunk/gdata/tests/runit.getDateTimeParts.R) =================================================================== --- trunk/gdata/inst/unitTests/runit.getDateTimeParts.R (rev 0) +++ trunk/gdata/inst/unitTests/runit.getDateTimeParts.R 2014-04-05 02:23:45 UTC (rev 1784) @@ -0,0 +1,119 @@ +### runit.getDateTimeParts.R +###------------------------------------------------------------------------ +### What: Extract date and time parts from ... - unit tests +### $Id$ +### Time-stamp: <2008-12-30 22:41:18 ggorjan> +###------------------------------------------------------------------------ + +### {{{ --- Test setup --- + +if(FALSE) { + library("RUnit") + library("gdata") +} + +num <- 1 +cha <- "a" +fac <- factor(c("A")) + +tYear <- as.character(c(2006, 1995, 1005, 3067)) +tMonth <- c("01", "04", "06", "12") +tDay <- c("01", "12", "22", "04") +tDate <- paste( paste(tYear, tMonth, tDay, sep="-"), "GMT" ) + +tHour <- c("05", "16", "20", "03") +tMin <- c("16", "40", "06", "52") +tSec <- c("56", "34", "05", "15") +tTime <- paste(tHour, tMin, tSec, sep=":") + +cDate <- as.Date(tDate) +cDatePOSIXct <- as.POSIXct(tDate) +cDatePOSIXlt <- as.POSIXlt(tDate) + +### }}} +### {{{ --- getYear --- + +test.getYear <- function() +{ + checkException(getYear(x=num)) + checkException(getYear(x=cha)) + checkException(getYear(x=fac)) + + checkIdentical(getYear(x=cDate), tYear) + checkIdentical(getYear(x=cDatePOSIXct), tYear) + checkIdentical(getYear(x=cDatePOSIXlt), tYear) +} + +### }}} +### {{{ --- getMonth --- + +test.getMonth <- function() +{ + checkException(getMonth(x=num)) + checkException(getMonth(x=cha)) + checkException(getMonth(x=fac)) + + checkIdentical(getMonth(x=cDate), tMonth) + checkIdentical(getMonth(x=cDatePOSIXct), tMonth) + checkIdentical(getMonth(x=cDatePOSIXlt), tMonth) +} + +### }}} +### {{{ --- getDay --- + +test.getDay <- function() +{ + checkException(getDay(x=num)) + checkException(getDay(x=cha)) + checkException(getDay(x=fac)) + + checkIdentical(getDay(x=cDate), tDay) + checkIdentical(getDay(x=cDatePOSIXct), tDay) + checkIdentical(getDay(x=cDatePOSIXlt), tDay) +} + +### }}} +### {{{ --- getHour --- + +test.getHour <- function() +{ + checkException(getHour(x=num)) + checkException(getHour(x=cha)) + checkException(getHour(x=fac)) + +## checkIdentical(getHour(x=cDate), tHour) +} + +### }}} +### {{{ --- getMin --- + +test.getMin <- function() +{ + checkException(getMin(x=num)) + checkException(getMin(x=cha)) + checkException(getMin(x=fac)) + +## checkIdentical(getMin(x=cDate), tMin) +} + +### }}} +### {{{ --- getSec --- + +test.getSec <- function() +{ + checkException(getSec(x=num)) + checkException(getSec(x=cha)) + checkException(getSec(x=fac)) + +## checkIdentical(getSec(x=cDate), tSec) +} + +### }}} +### {{{ Dear Emacs +### Local variables: +### folded-file: t +### end: +### }}} + +###------------------------------------------------------------------------ +### runit.getDateTimeParts.R ends here Copied: trunk/gdata/inst/unitTests/runit.mapLevels.R (from rev 1782, trunk/gdata/tests/runit.mapLevels.R) =================================================================== --- trunk/gdata/inst/unitTests/runit.mapLevels.R (rev 0) +++ trunk/gdata/inst/unitTests/runit.mapLevels.R 2014-04-05 02:23:45 UTC (rev 1784) @@ -0,0 +1,281 @@ +### runit.mapLevels.R +###------------------------------------------------------------------------ +### What: Unit tests for mapLevels et al. +### $Id$ +### Time-stamp: <2006-10-29 16:41:41 ggorjan> +###------------------------------------------------------------------------ + +### {{{ --- Test setup --- + +if(FALSE) { + library("RUnit") + library("gdata") +} + +### }}} +### {{{ mapLevels, is.*, as.*, [.* + +test.mapLevels <- function() +{ + ## Integer and numeric + checkException(mapLevels(1:3)) # wrong class(x) + checkException(mapLevels(1.5)) # wrong class(x) + + ## Factor + f <- factor(c("B", "C", "A")) + fMapInt <- list(A=as.integer(1), B=as.integer(2), C=as.integer(3)) + fMapInt1 <- list(B=as.integer(1), C=as.integer(2)) + fMapCha <- list(A="A", B="B", C="C") + fMapInt <- as.levelsMap(fMapInt) + fMapInt1 <- as.levelsMap(fMapInt1) + fMapCha <- as.levelsMap(fMapCha) + fMapCha1 <- fMapCha[c(1, 3)] # this will test also [.levelsMap + checkIdentical(mapLevels(f), fMapInt) + checkTrue(is.levelsMap(mapLevels(f))) # test for is.levelsMap + checkTrue(is.levelsMap(fMapInt)) # test for as.levelsMap + checkTrue(!gdata:::.isCharacterMap(fMapInt)) + checkIdentical(mapLevels(f, sort=FALSE), fMapInt) # sort is not used for factors + checkIdentical(mapLevels(f[1:2], drop=TRUE), fMapInt1) + checkIdentical(mapLevels(f, codes=FALSE), fMapCha) + checkIdentical(mapLevels(f[c(2, 3)], drop=TRUE, codes=FALSE), fMapCha1) + + ## Character + cha <- c("Z", "M", "A") + chaMapInt <- list(A=as.integer(1), M=as.integer(2), Z=as.integer(3)) + chaMapIntO <- list(Z=as.integer(1), M=as.integer(2), A=as.integer(3)) + chaMapInt1 <- list(M=as.integer(1), Z=as.integer(2)) + chaMapCha <- list(A="A", M="M", Z="Z") + chaMapInt <- as.levelsMap(chaMapInt) + chaMapIntO <- as.levelsMap(chaMapIntO) + chaMapInt1 <- as.levelsMap(chaMapInt1) + chaMapCha <- as.levelsMap(chaMapCha) + checkIdentical(mapLevels(cha), chaMapInt) + checkIdentical(mapLevels(cha, sort=FALSE), chaMapIntO) # sort works for characters + checkIdentical(mapLevels(cha[1:2], drop=TRUE), chaMapInt1) + checkIdentical(mapLevels(cha, codes=FALSE), chaMapCha) + + ## List + l <- list(f=f, cha=cha) + l1 <- list(cha=cha, f=f) + l2 <- list(cha=cha, f=f, i=1:10) + lMapInt <- list(f=fMapInt, cha=chaMapInt) + lMapCha <- list(f=fMapCha, cha=chaMapCha) + lMapInt <- as.listLevelsMap(lMapInt) + lMapCha <- as.listLevelsMap(lMapCha) + lMapChaC <- as.list(sort(unique(c(cha, as.character(f))))) + lMapChaCO <- as.list(unique(c(cha, as.character(f)))) + names(lMapChaC) <- unlist(lMapChaC) + names(lMapChaCO) <- unlist(lMapChaCO) + lMapChaC <- as.levelsMap(lMapChaC) + lMapChaCO <- as.levelsMap(lMapChaCO) + checkIdentical(mapLevels(l), lMapInt) + checkTrue(is.listLevelsMap(mapLevels(l))) # test for is.listLevelsMap + checkTrue(is.listLevelsMap(lMapInt)) # test for as.listLevelsMap + checkIdentical(mapLevels(l, codes=FALSE), lMapCha) + checkException(mapLevels(l, combine=TRUE)) # can not combine integer maps + checkIdentical(mapLevels(l, codes=FALSE, combine=TRUE), lMapChaC) + checkIdentical(mapLevels(l1, codes=FALSE, combine=TRUE), lMapChaC) + checkIdentical(mapLevels(l1, codes=FALSE, combine=TRUE, sort=FALSE), lMapChaCO) + checkException(mapLevels(l2)) # only char and factor + + ## Data.frame + df <- data.frame(f1=factor(c("G", "Abc", "Abc", "D", "F")), + f2=factor(c("Abc", "Abc", "B", "D", "K")), + cha=c("jkl", "A", "D", "K", "L"), + int=1:5) + dfMapInt <- list(f1=mapLevels(df$f1), f2=mapLevels(df$f2), cha=mapLevels(df$cha)) + dfMapInt <- as.listLevelsMap(dfMapInt) + dfMapInt1 <- dfMapInt[c(1, 3)] # this will test also [.listLevelsMap + checkException(mapLevels(df)) # wrong class of int + checkIdentical(mapLevels(df[, 1:3]), dfMapInt) + checkIdentical(mapLevels(df[, c(1, 3)]), dfMapInt1) +} + +### }}} +### {{{ .check* + +test.checkLevelsMap <- function(x) +{ + ## --- levelsMap --- + + ## not a list + checkException(gdata:::.checkLevelsMap(x="A", method="raw")) + ## list without names + checkException(gdata:::.checkLevelsMap(x=list("A"), method="raw")) + fMapInt <- list(A=as.integer(1), B=as.integer(2), C=as.integer(3)) + ## x should be levelsMap + checkException(gdata:::.checkLevelsMap(x=fMapInt, method="class")) + + ## --- listLevelsMap --- + + map <- list(as.levelsMap(fMapInt), as.levelsMap(fMapInt)) + map1 <- list(fMapInt, fMapInt) + class(map1) <- "listLevelsMap" + ## x should be a listLevelsMap + checkException(gdata:::.checkListLevelsMap(x=map, method="class")) + ## x should be also a list of levelsMaps + checkException(gdata:::.checkListLevelsMap(x=map1, method="class")) + ## the rest is done with levelsMap tests +} + +### }}} +### {{{ c.* + +test.cLevelsMap <- function() +{ + f1 <- factor(letters[c(2, 1)]) + f2 <- factor(letters[c(3, 1, 2)]) + mapCha1 <- mapLevels(f1, codes=FALSE) # get maps + mapCha2 <- mapLevels(f2, codes=FALSE) + mapCha1S <- mapLevels(as.character(f1), codes=FALSE, sort=FALSE) + mapCha2S <- mapLevels(as.character(f2), codes=FALSE, sort=FALSE) + mapChaTest <- list(a="a", b="b") + mapChaTest1 <- list(a="a", b="b", c="c") + mapChaTest2 <- list(c="c", a="a", b="b") + class(mapChaTest) <- class(mapChaTest1) <- class(mapChaTest2) <- "levelsMap" + mapChaTest3 <- list(mapChaTest, mapChaTest1, mapChaTest, mapChaTest1) + class(mapChaTest3) <- "listLevelsMap" + checkIdentical(c(mapCha1), mapChaTest) + checkIdentical(c(mapCha2, mapCha1), mapChaTest1) + checkIdentical(c(mapCha2S, mapCha1S, sort=FALSE), mapChaTest2) + + l <- list(f1, f2) + mapCha <- mapLevels(l, codes=FALSE) + checkIdentical(c(mapCha, mapCha), mapChaTest3) + checkIdentical(c(mapCha, recursive=TRUE), mapChaTest1) + + checkException(c(mapLevels(f1))) # can not combine integer “levelsMaps” + + ## Example with maps of different length of components + map1 <- list(A=c("a", "e", "i", "o", "u"), B="b", C="c", C="m", + D=c("d", "e"), F="f") + map2 <- list(A=c("a", "z", "w", "y", "x"), F="f", G=c("g", "h", "j"), + i="i", k=c("k", "l"), B="B") + map0Test <- list(A=c("a", "e", "i", "o", "u"), B="b", C="c", C="m", + D=c("d", "e"), F="f", + A=c("z", "w", "y", "x"), G=c("g", "h", "j"), + i="i", k=c("k", "l"), B="B") + map0Test <- as.levelsMap(map0Test) + mapTest <- sort(map0Test) + map1 <- as.levelsMap(map1) + map2 <- as.levelsMap(map2) + map <- c(map1, map2) + map0 <- c(map1, map2, sort=FALSE) + checkIdentical(map, mapTest) + checkIdentical(map0, map0Test) +} + +### }}} +### {{{ unique + +test.uniqueLevelsMap <- function() +{ + map <- list(A=c(1, 2, 1, 3), B=4, C=1, C=5, D=c(6, 8), E=7, B=4, + D=c(6, 8)) + map1 <- map + map1[[1]] <- map[[1]][c(1, 2, 4)] + map1[[7]] <- NULL # remove B=4 + map1[[7]] <- NULL # remove D=c(6, 8) + ## unique (used in as.levelsMap), will remove duplicates (A=1) + checkIdentical(as.levelsMap(map1), as.levelsMap(map)) +} + +### }}} +### {{{ mapLevels<- + +"test.mapLevels<-" <- function() +{ + ## Some errors + checkException("mapLevels<-"(1.1, value=2)) # wrong class(x) + checkException("mapLevels<-"(complex(1.1), value=2)) # wrong class(x) + + f <- factor(c("A", "B", "C")) + fMapInt <- mapLevels(f) + ## can not apply integer "levelsMap" to "character" + checkException("mapLevels<-"(as.character(f), value=fMapInt)) + + fMapCha <- mapLevels(f, codes=FALSE) + ## can not apply character levelsMap to "integer" + checkException("mapLevels<-"(as.integer(f), value=chaMapCha)) + + fMapFuzz <- fMapInt + fMapFuzz[[1]] <- "A" + ## all components of 'value' must be of the same class + checkException("mapLevels<-"(as.character(f), value=fMapFuzz)) + checkException("mapLevels<-"(as.integer(f), value=fMapFuzz)) + + ## x integer, value integer levelsMap + f <- factor(letters[c(10, 15, 1, 2)]) + fMapInt <- mapLevels(f) + fInt <- as.integer(f) + mapLevels(fInt) <- fMapInt + checkIdentical(fInt, f) + + ## x factor, value integer levelsMap + fInt <- factor(as.integer(f)) + mapLevels(fInt) <- fMapInt + checkIdentical(fInt, f) + + ## above is essentially the same as levels<-.factor + fInt1 <- factor(as.integer(f)) + levels(fInt1) <- fMapInt + checkIdentical(fInt1, f) + + ## x character, value character levelsMap + cha <- c("B", "A", "C") + chaMapCha <- as.levelsMap(list(A1="A", B2="B", C3="C")) + mapLevels(cha) <- chaMapCha + chaTest <- factor(c("B2", "A1", "C3")) + checkIdentical(cha, chaTest) + ## and a bit more for components of length > 1 + cha <- c("G", "I", "B", "A", "C", "D", "Z") + chaMapCha <- as.levelsMap(list(A1=c("A", "G", "I"), B2="B", C3=c("C", "D"))) + mapLevels(cha) <- chaMapCha + chaTest <- factor(c("A1", "A1", "B2", "A1", "C3", "C3", NA)) + checkIdentical(cha, chaTest) + + ## x factor, value character levelsMap + f <- factor(c("G", "I", "B", "A", "C", "D", "Z")) + fMapCha <- as.levelsMap(list(A1=c("A", "G", "I"), B2="B", C3=c("C", "D"))) + mapLevels(f) <- fMapCha + fTest <- factor(c("A1", "A1", "B2", "A1", "C3", "C3", NA)) + checkIdentical(f, fTest) + + ## Two factors and character map + f1 <- factor(letters[1:10]) + f2 <- factor(letters[5:14]) + checkIdentical(as.integer(f1), as.integer(f2)) # the same integer codes + mapCha1 <- mapLevels(f1, codes=FALSE) # get maps + mapCha2 <- mapLevels(f2, codes=FALSE) + mapCha <- c(mapCha1, mapCha2) # combine maps + ## apply map + mapLevels(f1) <- mapCha # the same as levels(f1) <- mapCha + mapLevels(f2) <- mapCha # the same as levels(f2) <- mapCha + checkIdentical(as.integer(f1), 1:10) # \ internal codes are now + checkIdentical(as.integer(f2), 5:14) # / "consistent" among factors + + ## The same with list + l <- list(f1=f1, f2=f2) + mapCha <- mapLevels(l, codes=FALSE, combine=TRUE) + mapLevels(l) <- mapCha + checkIdentical(as.integer(l$f1), 1:10) # \ internal codes are now + checkIdentical(as.integer(l$f2), 5:14) # / "consistent" among factors + + ## and data.frame + df <- data.frame(f1=f1, f2=f2) + mapCha <- mapLevels(df, codes=FALSE, combine=TRUE) + mapLevels(df) <- mapCha + checkIdentical(as.integer(df$f1), 1:10) # \ internal codes are now + checkIdentical(as.integer(df$f2), 5:14) # / "consistent" among factors + +} + +### }}} +### {{{ Dear Emacs +## Local variables: +## folded-file: t +## End: +### }}} + +###------------------------------------------------------------------------ +### runit.mapLevels.R ends here Copied: trunk/gdata/inst/unitTests/runit.nPairs.R (from rev 1782, trunk/gdata/tests/runit.nPairs.R) =================================================================== --- trunk/gdata/inst/unitTests/runit.nPairs.R (rev 0) +++ trunk/gdata/inst/unitTests/runit.nPairs.R 2014-04-05 02:23:45 UTC (rev 1784) @@ -0,0 +1,68 @@ +### runit.nPairs.R +###------------------------------------------------------------------------ +### What: Number of variable pairs - unit tests +### $Id$ +### Time-stamp: <2008-12-30 18:24:59 ggorjan> +###------------------------------------------------------------------------ + +### {{{ --- Test setup --- + +if(FALSE) { + library("RUnit") + library("gdata") +} + +### }}} +### {{{ --- nPairs --- + +test.nPairs <- function() +{ + ## 'x' must be a data.frame or a matrix + x <- rpois(100, lambda=10) + checkException(nPairs(x=x)) + checkException(nPairs(x=table(x))) + + test <- data.frame(V1=c(1, 2, 3, 4, 5), + V2=c(NA, 2, 3, 4, 5), + V3=c(1, NA, NA, NA, NA), + V4=c(1, 2, 3, NA, NA)) + testCheck <- matrix(data=as.integer(c(5, 4, 1, 3, + 4, 4, 0, 2, + 1, 0, 1, 1, + 3, 2, 1, 3)), + nrow=4, ncol=4, byrow=TRUE) + class(testCheck) <- c("nPairs", class(testCheck)) + + testCheckNames <- testCheck + colnames(testCheckNames) <- rownames(testCheckNames) <- colnames(test) + + checkIdentical(nPairs(x=test), testCheckNames) + checkIdentical(nPairs(x=test, names=FALSE), testCheck) + checkIdentical(nPairs(x=as.matrix(test)), testCheckNames) + checkIdentical(nPairs(x=as.matrix(test), names=FALSE), testCheck) + + testCheck <- cbind(testCheckNames, as.integer(c(5, 4, 0, 0))) + class(testCheck) <- class(testCheckNames) + colnames(testCheck) <- c(colnames(test), "all") + checkIdentical(nPairs(x=test, margin=TRUE), testCheck) + + testCheckSumm <- matrix(data=as.integer(c(0, 1, 4, 2, + 0, 0, 4, 2, + 0, 1, 0, 0, + 0, 1, 2, 0)), + nrow=4, ncol=4, byrow=TRUE) + dimnames(testCheckSumm) <- dimnames(testCheckNames) + tmp <- summary(nPairs(x=test)) + checkEquals(tmp, testCheckSumm) +} + + +### }}} +### {{{ Dear Emacs +### Local variables: +### folded-file: t +### end: +### }}} + +###------------------------------------------------------------------------ +### runit.nPairs.R ends here Copied: trunk/gdata/inst/unitTests/runit.reorder.factor.R (from rev 1782, trunk/gdata/tests/runit.reorder.factor.R) =================================================================== --- trunk/gdata/inst/unitTests/runit.reorder.factor.R (rev 0) +++ trunk/gdata/inst/unitTests/runit.reorder.factor.R 2014-04-05 02:23:45 UTC (rev 1784) @@ -0,0 +1,64 @@ +### runit.reorder.factor.R +###------------------------------------------------------------------------ +### What: Tests for reorder.factor +### $Id$ +### Time-stamp: <2006-10-30 18:25:05 ggorjan> +###------------------------------------------------------------------------ + +### {{{ --- Test setup --- + +if(FALSE) { + library("RUnit") + library("gdata") +} + +### }}} +### {{{ --- reorder.factor --- + +test.reorder.factor <- function() +{ + tmp <- Sys.getlocale(category="LC_COLLATE") + Sys.setlocale(category="LC_COLLATE", locale="C") + + ## Create a 4 level example factor + levs <- c("PLACEBO", "300 MG", "600 MG", "1200 MG") + trt <- factor(rep(x=levs, times=c(22, 24, 28, 26))) + + ## Change the order to something useful + ## default "mixedsort" ordering + trt2 <- reorder(trt) + levsTest <- c("300 MG", "600 MG", "1200 MG", "PLACEBO") + checkIdentical(levels(trt2), levsTest) + + ## using indexes: + trt3 <- reorder(trt, new.order=c(4, 2, 3, 1)) + levsTest <- c("PLACEBO", "300 MG", "600 MG", "1200 MG") + checkIdentical(levels(trt3), levsTest) + + ## using label names: + trt4 <- reorder(trt, new.order=c("PLACEBO", "300 MG", "600 MG", "1200 MG")) + levsTest <- c("PLACEBO", "300 MG", "600 MG", "1200 MG") + checkIdentical(levels(trt4), levsTest) + + ## using frequency + trt5 <- reorder(trt, X=as.numeric(trt), FUN=length) + levsTest <- c("PLACEBO", "300 MG", "1200 MG", "600 MG") + checkIdentical(levels(trt5), levsTest) + + ## drop out the '300 MG' level + trt6 <- reorder(trt, new.order=c("PLACEBO", "600 MG", "1200 MG")) + levsTest <- c("PLACEBO", "600 MG", "1200 MG") + checkIdentical(levels(trt6), levsTest) + + Sys.setlocale(category="LC_COLLATE", locale=tmp) +} + +### }}} +### {{{ Dear Emacs +## Local variables: +## folded-file: t +## End: +### }}} + +###------------------------------------------------------------------------ +### runit.reorder.factor.R ends here Copied: trunk/gdata/inst/unitTests/runit.trim.R (from rev 1782, trunk/gdata/tests/runit.trim.R) =================================================================== --- trunk/gdata/inst/unitTests/runit.trim.R (rev 0) +++ trunk/gdata/inst/unitTests/runit.trim.R 2014-04-05 02:23:45 UTC (rev 1784) @@ -0,0 +1,55 @@ +### runit.trim.R +###------------------------------------------------------------------------ +### What: Tests for trim +### $Id$ +### Time-stamp: <2006-08-29 14:21:02 ggorjan> +###------------------------------------------------------------------------ + +### {{{ --- Test setup --- + +if(FALSE) { + library("RUnit") + library("gdata") +} + +### }}} +### {{{ --- trim --- + +test.trim <- function() +{ + tmp <- Sys.getlocale(category="LC_COLLATE") + Sys.setlocale(category="LC_COLLATE", locale="C") + + sTrim <- " this is an example string " + sTrimR <- "this is an example string" + + fTrim <- factor(c(sTrim, sTrim, " A", " B ", " C ", "D ")) + fTrimR <- factor(c(sTrimR, sTrimR, "A", "B", "C", "D")) + + lTrim <- list(s=rep(sTrim, times=6), f=fTrim, i=1:6) + lTrimR <- list(s=rep(sTrimR, times=6), f=fTrimR, i=1:6) + + dfTrim <- as.data.frame(lTrim) + dfTrimR <- as.data.frame(lTrimR) + + checkIdentical(trim(sTrim), sTrimR) + checkIdentical(trim(fTrim), fTrimR) + checkIdentical( + levels(trim(fTrim, recode.factor=FALSE)), + c("this is an example string", "C", "A", "B", "D") + ) + checkIdentical(trim(lTrim), lTrimR) + checkIdentical(trim(dfTrim), dfTrimR) + + Sys.setlocale(category="LC_COLLATE", locale=tmp) +} + +### }}} +### {{{ Dear Emacs +## Local variables: +## folded-file: t +## End: +### }}} + +###------------------------------------------------------------------------ +### runit.trim.R ends here Copied: trunk/gdata/inst/unitTests/runit.trimSum.R (from rev 1782, trunk/gdata/tests/runit.trimSum.R) =================================================================== --- trunk/gdata/inst/unitTests/runit.trimSum.R (rev 0) +++ trunk/gdata/inst/unitTests/runit.trimSum.R 2014-04-05 02:23:45 UTC (rev 1784) @@ -0,0 +1,61 @@ +### runit.trimSum.R +###------------------------------------------------------------------------ +### What: Unit tests for trimSum +### $Id$ +### Time-stamp: <2008-12-20 11:58:50 ggorjan> +###------------------------------------------------------------------------ + +### {{{ --- Test setup --- + +if(FALSE) { + library("RUnit") + library("gdata") +} + +### }}} +### {{{ --- trimSum --- + +test.trimSum <- function() +{ + + ## 'x' must be a vector - for now + checkException(trimSum(matrix(1:10))) + checkException(trimSum(data.frame(1:10))) + checkException(trimSum(list(1:10))) + + ## 'x' must be numeric + checkException(trimSum(letters)) + + ## 'n' must be smaller than the length of x + checkException(trimSum(x=1:10, n=11)) + checkException(trimSum(x=1, n=1)) + + ## Default + x <- trimSum(x=1:10, n=5) + x2 <- c(1:4, 45) + checkEquals(x, x2) + + ## Left + x <- trimSum(x=1:10, n=5, right=FALSE) + x2 <- c(21, 7:10) + checkEquals(x, x2) + + ## NA + x <- trimSum(x=c(1:9, NA), n=5) + x2 <- c(1:4, NA) + checkEquals(x, x2) + + x <- trimSum(x=c(1:9, NA), n=5, na.rm=TRUE) + x2 <- c(1:4, 35) + checkEquals(x, x2) +} + +### }}} +### {{{ Dear Emacs +## Local variables: +## folded-file: t +## End: +### }}} + +###------------------------------------------------------------------------ +### runit.trimSum.R ends here Copied: trunk/gdata/inst/unitTests/runit.unknown.R (from rev 1783, trunk/gdata/tests/runit.unknown.R) =================================================================== --- trunk/gdata/inst/unitTests/runit.unknown.R (rev 0) +++ trunk/gdata/inst/unitTests/runit.unknown.R 2014-04-05 02:23:45 UTC (rev 1784) @@ -0,0 +1,531 @@ +### runit.unknown.R +###------------------------------------------------------------------------ +### What: Tests for Change given unknown value to NA and vice versa methods +### $Id$ +### Time-stamp: <2006-10-30 17:46:21 ggorjan> +###------------------------------------------------------------------------ + +### {{{ --- Test setup --- + +library("RUnit") +library("gdata") + + +### {{{ --- Vectors --- + +intUnk <- 9999 +xInt <- as.integer(c(NA, 1:2, NA, 5, 6, 7, 8, 9)) +xIntUnk <- as.integer(c(intUnk, 1:2, intUnk, 5, 6, 7, 8, 9)) +xIntUnkTest <- xIntUnk %in% intUnk + +numUnk <- 0 +xNum <- c(9999, NA, 1.5, NA, 5, 6, 7, 8, 9) +xNumUnk <- c(9999, 0, 1.5, 0, 5, 6, 7, 8, 9) +xNumUnkTest <- xNumUnk %in% numUnk + +chaUnk <- "notAvail" +chaUnk1 <- "-" +xCha <- c("A", "B", NA, "C", NA, "-", "7", "8", "9") +xChaUnk <- c("A", "B", chaUnk, "C", chaUnk, "-", "7", "8", "9") +xChaUnk1 <- c("A", "B", chaUnk1, "C", chaUnk1, "-", "7", "8", "9") +xChaUnkTest <- xChaUnk %in% chaUnk +xChaUnk1Test <- xChaUnk %in% chaUnk1 + +facUnk <- "notAvail" +facUnk1 <- "NA" +xFac <- factor(c("A", "0", 0, "NA", "NA", intUnk, numUnk, "-", NA)) +xFacUnk <- factor(c("A", "0", 0, "NA", "NA", intUnk, numUnk, "-", facUnk)) +xFacUnk1 <- factor(c("A", "0", 0, "NA", "NA", intUnk, numUnk, "-", facUnk1)) +xFacUnkTest <- c(0, 0, 0, 0, 0, 0, 0, 0, 1) +xFacUnkTest <- as.logical(xFacUnkTest) +xFacUnk1Test <- c(0, 0, 0, 1, 1, 0, 0, 0, 1) +xFacUnk1Test <- as.logical(xFacUnk1Test) +xFac1 <- factor(c("A", "0", 0, NA, NA, intUnk, numUnk, "-", NA)) + +facLev <- "A" +xFacUnkLev <- factor(c("A", "0", 0, "NA", "NA", intUnk, numUnk, "-", "A")) +xFacUnkLevTest <- c(1, 0, 0, 0, 0, 0, 0, 0, 1) +xFacUnkLevTest <- as.logical(xFacUnkLevTest) + +dateUnk <- as.Date("2006-08-14") +tmp <- as.Date("2006-08-15") +xDate <- c(tmp, NA) +xDateUnk <- c(tmp, dateUnk) +xDateTest <- c(FALSE, TRUE) + +xDate1Unk <- c(tmp, dateUnk, NA) +xDate1Test <- c(FALSE, TRUE, FALSE) + +POSIXltUnk <- strptime("2006-08-14", format="%Y-%m-%d") +tmp <- strptime("2006-08-15", format="%Y-%m-%d") +xPOSIXlt <- c(tmp, NA) +xPOSIXltUnk <- c(tmp, POSIXltUnk) +xPOSIXltTest <- c(FALSE, TRUE) + +xPOSIXlt1Unk <- c(tmp, POSIXltUnk, NA) +xPOSIXlt1Test <- c(FALSE, TRUE, FALSE) + +POSIXctUnk <- as.POSIXct(strptime("2006-08-14 01:01:01", format="%Y-%m-%d %H:%M:%S")) +tmp <- as.POSIXct(strptime("2006-08-15 01:01:01", format="%Y-%m-%d %H:%M:%S")) +xPOSIXct <- c(tmp, NA) +xPOSIXctUnk <- c(tmp, POSIXctUnk) +xPOSIXctTest <- xPOSIXltTest + +xPOSIXct1Unk <- c(tmp, POSIXctUnk, NA) +xPOSIXct1Test <- xPOSIXlt1Test + +### }}} +### {{{ --- Lists and data.frames --- + +xList <- list(xInt, xCha, xNum, xFac) +xListN <- list(int=xInt, cha=xCha, num=xNum, fac=xFac) +xListUnk <- list(xIntUnk, xChaUnk, xNumUnk, xFacUnk) +xListUnkTest <- list(xIntUnkTest, xChaUnkTest, xNumUnkTest, xFacUnkTest) +xListNUnk <- list(int=xIntUnk, cha=xChaUnk, num=xNumUnk, fac=xFacUnk) +xListNUnkTest <- list(int=xIntUnkTest, cha=xChaUnkTest, num=xNumUnkTest, fac=xFacUnkTest) + +xDF <- as.data.frame(xListN) +xDF$cha <- as.character(xDF$cha) +xDFUnk <- as.data.frame(xListNUnk) +xDFUnk$cha <- as.character(xDFUnk$cha) +xDFUnkTest <- as.data.frame(xListNUnkTest) + +unkC <- c(intUnk, chaUnk, numUnk, facUnk) +unkL <- list(intUnk, chaUnk, numUnk, facUnk) +unkLN <- list(num=numUnk, cha=chaUnk, fac=facUnk, int=intUnk) ## mixed as it is named +unkLMN <- list(cha=chaUnk, int=intUnk, num=c(intUnk, numUnk), + fac=c(chaUnk1, facUnk)) + +xListMNUnkF <- list(int=as.integer(c(9999, 1, 2, 9999, 5, 6, 7, 8, 9)), + cha=c("A", "B", "notAvail", "C", "notAvail", "-", "7", "8", "9"), + num=c(9999, 0, 1.5, 0, 5, 6, 7, 8, 9), + fac=factor(c("A", "0", "0", "NA", "NA", 9999, "0", "-", "notAvail"))) +xListMNUnkFTest <- list(int=c(1, 0, 0, 1, 0, 0, 0, 0, 0), + cha=c(0, 0, 1, 0, 1, 0, 0, 0, 0), + num=c(1, 1, 0, 1, 0, 0, 0, 0, 0), + fac=c(0, 0, 0, 0, 0, 0, 0, 1, 1)) +xListMNUnkFTest <- lapply(xListMNUnkFTest, as.logical) +xListMNF <- list(int=as.integer(c(NA, 1, 2, NA, 5, 6, 7, 8, 9)), + cha=c("A", "B", NA, "C", NA, "-", "7", "8", "9"), + num=c(NA, NA, 1.5, NA, 5, 6, 7, 8, 9), + fac=factor(c("A", "0", "0", "NA", "NA", "9999", "0", NA, NA))) + +xDFMUnkF <- as.data.frame(xListMNUnkF) +xDFMUnkF$cha <- as.character(xDFMUnkF$cha) +xDFMUnkFTest <- as.data.frame(xListMNUnkFTest) +xDFMF <- as.data.frame(xListMNF) +xDFMF$cha <- as.character(xDFMF$cha) + +unk1 <- 555555 +xListUnk1 <- list(as.integer(c(unk1, 1, 2, unk1, 5, 6, 7, 8, 9)), + c("A", "B", unk1, "C", unk1, "-", "7", "8", "9"), + c(9999, unk1, 1.5, unk1, 5, 6, 7, 8, 9), + factor(c("A", "0", "0", "NA", "NA", "9999", "0", "-", unk1))) +xListUnk1Test <- lapply(xListUnk1, function(x) x %in% unk1) +xListNUnk1 <- xListUnk1 +names(xListNUnk1) <- c("int", "cha", "num", "fac") +xDFUnk1 <- as.data.frame(xListNUnk1) +xDFUnk1$cha <- as.character(xDFUnk1$cha) +xDFUnk1Test <- as.data.frame(xListUnk1Test) +names(xDFUnk1Test) <- names(xListNUnk1) + +unkC2 <- c(0, "notAvail") +xListUnk2 <- list(as.integer(c(unkC2[1], 1, 2, unkC2[1], 5, 6, 7, 8, 9)), + c("A", "B", unkC2[2], "C", unkC2[2], "-", "7", "8", "9"), + c(9999, as.numeric(unkC2[1]), 1.5, as.numeric(unkC2[1]), 5, 6, 7, 8, 9), + factor(c("A", "0", "0", "NA", "NA", "9999", "0", "-", unkC2[2]))) +xListNUnk2 <- xListUnk2 +names(xListNUnk2) <- c("int", "cha", "num", "fac") +xDFUnk2 <- as.data.frame(xListNUnk2) +xDFUnk2$cha <- as.character(xDFUnk2$cha) + +xListUnk2Test <- xListUnk2 +xListUnk2Test[[1]] <- xListUnk2Test[[1]] %in% unkC2[1] +xListUnk2Test[[2]] <- xListUnk2Test[[2]] %in% unkC2[2] +xListUnk2Test[[3]] <- xListUnk2Test[[3]] %in% unkC2[1] +xListUnk2Test[[4]] <- xListUnk2Test[[4]] %in% unkC2[2] +xListNUnk2Test <- xListUnk2Test +names(xListNUnk2Test) <- names(xListNUnk2) +xDFUnk2Test <- as.data.frame(xListNUnk2Test) + +unkL2 <- as.list(unkC2) +unkLN2 <- unkL2[c(2, 1)] +names(unkLN2) <- c("cha", "int") +xListUnk2a <- list(as.integer(c(NA, 1, 2, NA, 5, 6, 7, 8, 9)), + c("A", "B", unkLN2[[2]], "C", unkLN2[[2]], "-", "7", "8", "9"), + c(9999, NA, 1.5, NA, 5, 6, 7, 8, 9), + factor(c("A", "0", "0", "NA", "NA", "9999", "0", "-", unkLN2[[2]]))) +xListUnk2aTest <- xListUnk2a +xListUnk2aTest[[1]] <- xListUnk2aTest[[1]] %in% unkLN2[1] +xListUnk2aTest[[2]] <- xListUnk2aTest[[2]] %in% unkLN2[2] +xListUnk2aTest[[3]] <- xListUnk2aTest[[3]] %in% unkLN2[1] +xListUnk2aTest[[4]] <- xListUnk2aTest[[4]] %in% unkLN2[2] + +xList2a <- list(xListUnk2a[[1]], + c("A", "B", NA, "C", NA, "-", "7", "8", "9"), + xListUnk2a[[3]], + factor(c("A", NA, NA, "NA", "NA", 9999, NA, "-", NA))) + +### }}} +### {{{ --- Matrix --- + +matUnk <- 9999 +mat <- matrix(1:25, nrow=5, ncol=5) +mat[1, 2] <- NA; mat[1, 4] <- NA; mat[2, 2] <- NA; +mat[3, 2] <- NA; mat[3, 5] <- NA; mat[5, 4] <- NA; +matUnk1 <- mat +matUnk1[1, 2] <- matUnk; matUnk1[1, 4] <- matUnk; matUnk1[2, 2] <- matUnk; +matUnk1[3, 2] <- matUnk; matUnk1[3, 5] <- matUnk; matUnk1[5, 4] <- matUnk; +matUnkTest <- matUnk1Test <- is.na(mat) + +matUnk2Test <- matUnkTest | mat == 1 + +### }}} +### {{{ --- Use of unknown=list(.default=, ...) or similarly named vector --- + +D1 <- "notAvail" +unkLND1 <- list(.default=D1) +xListUnkD1 <- list(as.integer(c(NA, 1:2, NA, 5, 6, 7, 8, 9)), + c("A", "B", D1, "C", D1, "-", "7", "8", "9"), + c(9999, NA, 1.5, NA, 5, 6, 7, 8, 9), + factor(c("A", "0", 0, "NA", "NA", intUnk, numUnk, "-", D1))) +xListUnkD1Test <- lapply(xListUnkD1, function(x) x %in% D1) +xListD1 <- xList + +xListNUnkD1 <- xListUnkD1 +xListNUnkD1Test <- xListUnkD1Test +names(xListNUnkD1) <- names(xListNUnkD1Test) <- names(xListNUnk1) +xListND1 <- xListN + +DSO2 <- c("notAvail", 5678) +unkLNDSO2 <- as.list(DSO2) +names(unkLNDSO2) <- c(".default", "someOther") +xListUnkDSO2 <- list(as.integer(c(NA, 1:2, NA, 5, 6, 7, 8, 9)), + c("A", "B", DSO2[1], "C", DSO2[1], "-", "7", "8", "9"), + c(9999, NA, 1.5, NA, 5, 6, 7, 8, 9), + factor(c("A", "0", 0, "NA", "NA", intUnk, numUnk, "-", DSO2[2]))) +xListUnkDSO2Test <- lapply(xListUnkDSO2, function(x) x %in% DSO2) + +unkLND3 <- list(.default="notAvail", num=0, int=9999) +xListNUnkD3 <- list(int=as.integer(c(unkLND3[[3]], 1:2, unkLND3[[3]], 5, 6, 7, 8, 9)), + cha=c("A", "B", unkLND3[[1]], "C", unkLND3[[1]], "-", "7", "8", "9"), + num=c(9999, unkLND3[[2]], 1.5, unkLND3[[2]], 5, 6, 7, 8, 9), + fac=factor(c("A", "0", 0, "NA", "NA", intUnk, numUnk, "-", unkLND3[[1]]))) +xListNUnkD3Test <- xListNUnkD3 +xListNUnkD3Test$int <- xListNUnkD3Test$int %in% unkLND3[[3]] +xListNUnkD3Test$cha <- xListNUnkD3Test$cha %in% unkLND3[[1]] +xListNUnkD3Test$num <- xListNUnkD3Test$num %in% unkLND3[[2]] +xListNUnkD3Test$fac <- xListNUnkD3Test$fac %in% unkLND3[[1]] + +unkLND2E <- list(.default="notAvail", 9999) + +### }}} + +### }}} +### {{{ --- isUnknown --- + +test.isUnknown <- function() +{ + ## --- base methods for vectors --- + + ## base ... + checkIdentical(isUnknown(xIntUnk, unknown=as.integer(intUnk)), xIntUnkTest) + checkIdentical(isUnknown(xIntUnk, unknown=intUnk), xIntUnkTest) + checkIdentical(isUnknown(xNumUnk, unknown=numUnk), xNumUnkTest) + checkIdentical(isUnknown(xNumUnk, unknown=as.integer(numUnk)), xNumUnkTest) + checkIdentical(isUnknown(xChaUnk, unknown=chaUnk), xChaUnkTest) + checkIdentical(isUnknown(xFacUnk, unknown=facUnk), xFacUnkTest) + + ## multiple values are allowed for vector methods in vector or list form + checkIdentical(isUnknown(xIntUnk, unknown=unkC), xIntUnkTest) + checkIdentical(isUnknown(xIntUnk, unknown=unkL), xIntUnkTest) + + ## NA's in factors + checkIdentical(isUnknown(xFacUnk1, unknown=facUnk1), xFacUnk1Test) + facNA <- factor(c("0", 1, 2, 3, NA, "NA")) + facNATest <- c(FALSE, FALSE, FALSE, FALSE, TRUE, FALSE) + checkIdentical(isUnknown(facNA), facNATest) + + ## Date-time classes + checkIdentical(isUnknown(xDateUnk, unknown=dateUnk), xDateTest) + checkIdentical(isUnknown(xDate1Unk, unknown=dateUnk), xDate1Test) + checkIdentical(isUnknown(xPOSIXltUnk, unknown=POSIXltUnk), xPOSIXltTest) + checkIdentical(isUnknown(xPOSIXlt1Unk, unknown=POSIXltUnk), xPOSIXlt1Test) + checkIdentical(isUnknown(xPOSIXctUnk, unknown=POSIXctUnk), xPOSIXctTest) + checkIdentical(isUnknown(xPOSIXct1Unk, unknown=POSIXctUnk), xPOSIXct1Test) + + ## --- lists and data.frames --- + + ## with vector of single unknown values + checkIdentical(isUnknown(xListUnk, unknown=unkC), xListUnkTest) + checkIdentical(isUnknown(xDFUnk, unknown=unkC), xDFUnkTest) + + ## with list of single unknown values + checkIdentical(isUnknown(xListUnk, unknown=unkL), xListUnkTest) + checkIdentical(isUnknown(xDFUnk, unknown=unkL), xDFUnkTest) + + ## with named list of single unknown values + checkIdentical(isUnknown(xListNUnk, unknown=unkLN), xListNUnkTest) + checkIdentical(isUnknown(xDFUnk, unknown=unkLN), xDFUnkTest) + + ## with named list of multiple unknown values - valid here + checkIdentical(isUnknown(xListMNUnkF, unknown=unkLMN), xListMNUnkFTest) + checkIdentical(isUnknown(xDFMUnkF, unknown=unkLMN), xDFMUnkFTest) + + ## with single unknown value - recycling + checkIdentical(isUnknown(xListUnk1, unknown=unk1), xListUnk1Test) + checkIdentical(isUnknown(xDFUnk1, unknown=unk1), xDFUnk1Test) + + ## with vector of two unknown values - recycling + checkIdentical(isUnknown(xListUnk2, unknown=unkC2), xListUnk2Test) + checkIdentical(isUnknown(xDFUnk2, unknown=unkC2), xDFUnk2Test) + + ## with list of two unknown values - recycling + checkIdentical(isUnknown(xListUnk2, unknown=unkL2), xListUnk2Test) + checkIdentical(isUnknown(xDFUnk2, unknown=unkL2), xDFUnk2Test) + + ## list(.default=) + checkIdentical(isUnknown(x=xListUnkD1, unknown=unkLND1), xListUnkD1Test) + ## list(.default=, someOther=) we do not know someOther, but should work + ## as x is not named + checkIdentical(isUnknown(x=xListUnkDSO2, unknown=unkLNDSO2), xListUnkDSO2Test) + ## list(.default=) in named list + checkIdentical(isUnknown(x=xListNUnkD1, unknown=unkLND1), xListNUnkD1Test) + ## list(.default=, someOther=) OK if someOther is in the named list + checkIdentical(isUnknown(x=xListNUnkD3, unknown=unkLND3), xListNUnkD3Test) + ## list(.default=, 99) ERROR as we do not know where to apply 99 + checkException(isUnknown(x=xListNUnk, unknown=unkLND2E)) + + ## --- matrix --- + + checkIdentical(isUnknown(x=mat, unknown=NA), matUnkTest) + checkIdentical(isUnknown(x=matUnk1, unknown=matUnk), matUnkTest) + checkIdentical(isUnknown(x=matUnk1, unknown=c(1, matUnk)), matUnk2Test) +} + +### }}} +### {{{ --- unknownToNA --- + +test.unknownToNA <- function() +{ + ## --- base methods for vectors --- + + ## base ... + checkIdentical(unknownToNA(xIntUnk, as.integer(intUnk)), xInt) + checkIdentical(unknownToNA(xIntUnk, intUnk), xInt) ## with numeric + checkIdentical(unknownToNA(xNumUnk, numUnk), xNum) + checkIdentical(unknownToNA(xNumUnk, as.integer(numUnk)), xNum) + checkIdentical(unknownToNA(xChaUnk, chaUnk), xCha) + checkIdentical(unknownToNA(xChaUnk, chaUnk), xCha) + checkIdentical(unknownToNA(xFacUnk, facUnk), xFac) + + ## multiple values are allowed for vector methods in vector or list form + checkIdentical(unknownToNA(xIntUnk, unknown=unkC), xInt) + checkIdentical(unknownToNA(xIntUnk, unknown=unkL), xInt) + + ## NA's in factors + checkIdentical(unknownToNA(xFacUnk1, unknown=facUnk1), xFac1) + facNA <- factor(c("0", 1, 2, 3, NA, "NA")) + facNATest <- factor(c("0", 1, 2, 3, NA, NA)) + checkIdentical(unknownToNA(x=facNA, unknown="NA"), facNATest) + + ## Date-time classes + checkIdentical(unknownToNA(xDateUnk, unknown=dateUnk), xDate) + checkIdentical(unknownToNA(xPOSIXctUnk, unknown=POSIXctUnk), xPOSIXct) + + ## Per Brian Ripley on 2014-01-15: + ## + ## On platforms where POSIXlt has a gmtoff component, it does not need to be set. So + ## + ## > z$gmtoff + ## [1] 3600 NA + ## > xPOSIXltUnk$gmtoff + ## [1] 3600 3600 + ## + ## (or sometimes 0, not NA). + ## + ## So although identical() correctly reports that they differ, this + ## is allowed for optional components. + ## + ## It would also be wrong to use identical() to compare isdst + ## components: isdst = -1 means unknown. + ## + tmp_unknownToNA <- unknownToNA(xPOSIXltUnk, unknown=POSIXltUnk) + tmp_xPOSIXlt <- xPOSIXlt + + tmp_unknownToNA$gmtoff <- NULL # Remove $gmtoff to avoid comparison + tmp_xPOSIXlt$gmtoff <- NULL + + tmp_unknownToNA$isdst <- NULL # Remove $isdst to avoid comparison + tmp_xPOSIXlt$isdst <- NULL + + checkIdentical(tmp_unknownToNA, tmp_xPOSIXlt) + + + ## --- lists and data.frames --- + + ## with vector of single unknown values + checkIdentical(unknownToNA(xListUnk, unknown=unkC), xList) + checkIdentical(unknownToNA(xDFUnk, unknown=unkC), xDF) + + ## with list of single unknown values + checkIdentical(unknownToNA(xListUnk, unknown=unkL), xList) + checkIdentical(unknownToNA(xDFUnk, unknown=unkL), xDF) + + ## with named list of single unknown values + checkIdentical(unknownToNA(xListNUnk, unknown=unkLN), xListN) + checkIdentical(unknownToNA(xDFUnk, unknown=unkLN), xDF) + + ## with names list of multiple unknown values - must be an error + checkIdentical(unknownToNA(xListMNUnkF, unknown=unkLMN), xListMNF) + checkIdentical(unknownToNA(xDFMUnkF, unknown=unkLMN), xDFMF) + + ## with single unknown value - recycling + checkIdentical(unknownToNA(xListUnk1, unknown=unk1), xList) + checkIdentical(unknownToNA(xDFUnk1, unknown=unk1), xDF) + + ## with vector of two unknown values - recycling + checkIdentical(unknownToNA(xListUnk2, unknown=unkC2), xList) + checkIdentical(unknownToNA(xDFUnk2, unknown=unkC2), xDF) + + ## with list of two unknown values - recycling + checkIdentical(unknownToNA(xListUnk2, unknown=unkL2), xList) + checkIdentical(unknownToNA(xDFUnk2, unknown=unkL2), xDF) + + ## with named list of two unknown values but x is not named so named list + ## does not have any effect --> error as we do not know how to recycle + checkException(unknownToNA(xListUnk2a, unknown=unkLN2)) + + ## but we should get some results with named x + checkIdentical(unknownToNA(xListNUnk2, unknown=unkL2), xListN) + ## not also necesarilly with recycling of names lists, as it is + ## not clear how to properly recycle named lists (only names that match + ## can be really properly recycled) + checkException(unknownToNA(xListNUnk2, unknown=unkLN2)) + checkIdentical(unknownToNA(xDFUnk2, unknown=unkL2), xDF) + checkException(unknownToNA(xDFUnk2, unknown=unkLN2)) + + ## list(.default=) + checkIdentical(unknownToNA(x=xListUnkD1, unknown=unkLND1), xListD1) + ## list(.default=, someOther=) we do not know someOther, but should work + ## as x is not named + checkIdentical(unknownToNA(x=xListUnkDSO2, unknown=unkLNDSO2), xList) + ## list(.default=) in named list + checkIdentical(unknownToNA(x=xListNUnkD1, unknown=unkLND1), xListND1) + ## list(.default=, someOther=) OK if someOther is in the named list + checkIdentical(unknownToNA(x=xListNUnkD3, unknown=unkLND3), xListN) + ## list(.default=, 99) ERROR as we do not know where to apply 99 + checkException(unknownToNA(x=xListNUnk, unknown=unkLND2E)) + + ## --- matrix --- + + checkEquals(unknownToNA(x=matUnk1, unknown=matUnk), mat) +} + +### }}} +### {{{ --- NAToUnknown --- + +test.NAToUnknown <- function() +{ + ## --- base methods for vectors --- + + ## base ... + checkIdentical(NAToUnknown(xInt, as.integer(intUnk)), xIntUnk) + checkIdentical(NAToUnknown(xInt, intUnk), xIntUnk) ## with numeric + checkIdentical(NAToUnknown(xNum, numUnk), xNumUnk) + checkIdentical(NAToUnknown(xNum, as.integer(numUnk)), xNumUnk) + checkIdentical(NAToUnknown(xCha, chaUnk), xChaUnk) + checkIdentical(NAToUnknown(xCha, chaUnk), xChaUnk) + checkIdentical(NAToUnknown(xFac, facUnk), xFacUnk) + + ## only single values are allowed for vector methods + checkException(NAToUnknown(xInt, unknown=unkC)) + checkException(NAToUnknown(xInt, unknown=unkL)) + + ## and they should not already be in x unless force=TRUE + checkException(NAToUnknown(xCha, unknown=chaUnk1)) + checkIdentical(NAToUnknown(xCha, unknown=chaUnk1, force=TRUE), xChaUnk1) + + checkException(NAToUnknown(xFac, unknown=facLev)) + checkIdentical(NAToUnknown(xFac, unknown=facLev, force=TRUE), xFacUnkLev) + + ## NA's in factors + checkIdentical(NAToUnknown(xFac, unknown=facUnk1, force=TRUE), xFacUnk1) + facNA <- factor(c("0", 1, 2, 3, NA, NA)) + facNATest <- factor(c("0", 1, 2, 3, "NA", "NA")) + checkIdentical(NAToUnknown(x=facNA, unknown="NA"), facNATest) + + ## Date-time classes + checkIdentical(NAToUnknown(xDate, unknown=dateUnk), xDateUnk) + checkIdentical(NAToUnknown(xPOSIXlt, unknown=POSIXltUnk), xPOSIXltUnk) + checkIdentical(NAToUnknown(xPOSIXct, unknown=POSIXctUnk), xPOSIXctUnk) + + ## --- lists and data.frames --- + + ## with vector of single unknown values + checkIdentical(NAToUnknown(xList, unknown=unkC), xListUnk) + checkIdentical(NAToUnknown(xDF, unknown=unkC), xDFUnk) + + ## with list of single unknown values + checkIdentical(NAToUnknown(xList, unknown=unkL), xListUnk) + checkIdentical(NAToUnknown(xDF, unknown=unkL), xDFUnk) + + ## with named list of single unknown values + checkIdentical(NAToUnknown(xListN, unknown=unkLN), xListNUnk) + checkIdentical(NAToUnknown(xDF, unknown=unkLN), xDFUnk) + + ## with names list of multiple unknown values - must be an error + checkException(NAToUnknown(xListN, unknown=unkLMN)) + checkException(NAToUnknown(xDF, unknown=unkLMN)) + + ## with single unknown value - recycling + checkIdentical(NAToUnknown(xList, unknown=unk1), xListUnk1) + checkIdentical(NAToUnknown(xDF, unknown=unk1), xDFUnk1) + + ## with vector of two unknown values - recycling + checkIdentical(NAToUnknown(xList, unknown=unkC2), xListUnk2) + checkIdentical(NAToUnknown(xDF, unknown=unkC2), xDFUnk2) + + ## with list of two unknown values - recycling + checkIdentical(NAToUnknown(xList, unknown=unkL2), xListUnk2) + checkIdentical(NAToUnknown(xDF, unknown=unkL2), xDFUnk2) + + ## with named list of two unknown values but x is not named so named list + ## does not have any effect --> error as we do not know how to recycle + checkException(NAToUnknown(xList, unknown=unkLN2)) + + ## but we should get some results with named x + checkIdentical(NAToUnknown(xListN, unknown=unkL2), xListNUnk2) + ## not also necesarilly with recycling of names lists, as it is + ## not clear how to properly recycle named lists (only names that match + ## can be really properly recycled) + checkException(NAToUnknown(xListN, unknown=unkLN2)) + checkIdentical(NAToUnknown(xDF, unknown=unkL2), xDFUnk2) + checkException(NAToUnknown(xDF, unknown=unkLN2)) + + ## list(.default=) + checkIdentical(NAToUnknown(x=xList, unknown=unkLND1), xListUnkD1) + ## list(.default=, someOther=) we do not know someOther, but should work + ## as x is not named + checkIdentical(NAToUnknown(x=xList, unknown=unkLNDSO2), xListUnkDSO2) + ## list(.default=) in named list + checkIdentical(NAToUnknown(x=xListN, unknown=unkLND1), xListNUnkD1) + ## list(.default=, someOther=) OK if someOther is in the named list + checkIdentical(NAToUnknown(x=xListN, unknown=unkLND3), xListNUnkD3) + ## list(.default=, 99) ERROR as we do not know where to apply 99 + checkException(NAToUnknown(x=xListN, unknown=unkLND2E)) + + ## --- matrix --- + + checkEquals(NAToUnknown(x=mat, unknown=matUnk), matUnk1) +} + +### }}} +### {{{ Dear Emacs +### Local variables: +### folded-file: t +### End: +### }}} + +###------------------------------------------------------------------------ +### runit.unknown.R ends here Copied: trunk/gdata/inst/unitTests/runit.wideByFactor.R (from rev 1782, trunk/gdata/tests/runit.wideByFactor.R) =================================================================== --- trunk/gdata/inst/unitTests/runit.wideByFactor.R (rev 0) +++ trunk/gdata/inst/unitTests/runit.wideByFactor.R 2014-04-05 02:23:45 UTC (rev 1784) @@ -0,0 +1,55 @@ +### runit.wideByFactor.R +###------------------------------------------------------------------------ +### What: Reshape by factor levels - unit tests +### $Id$ +### Time-stamp: <2008-12-30 11:58:50 ggorjan> +###------------------------------------------------------------------------ + +### {{{ --- Test setup --- + +if(FALSE) { + library("RUnit") + library("gdata") +} + +### }}} +### {{{ --- wideByFactor --- + +test.wideByFactor <- function() +{ + n <- 10 + f <- 2 + tmp <- data.frame(y1=(1:n)/2, + y2=(n:1)*2, + f1=factor(rep(letters[1:f], n/2)), + f2=factor(c(rep(c("M"), n/2), rep(c("F"), n/2))), + c1=1:n, + c2=2*(1:n)) + + ## 'x' must be a data.frame + checkException(wideByFactor(x=1:10)) + checkException(wideByFactor(x=matrix(1:10))) + ## 'factor' can be only of length one + checkException(wideByFactor(x=tmp, factor=c("f1", "f2"))) + ## column defined in 'factor' must be a factor + checkException(wideByFactor(x=tmp, factor="c1")) + + tmp2 <- wideByFactor(x=tmp, factor="f1", common=c("c1", "c2"), sort=FALSE) + checkEquals(tmp2[c("c1", "c2")], tmp[c("c1", "c2")]) + checkEquals(names(tmp2), c("c1", "c2", "f1", "y1.a", "y2.a", "f2.a", "y1.b", "y2.b", "f2.b")) + checkEquals(tmp2$y1.a, c(0.5, NA, 1.5, NA, 2.5, NA, 3.5, NA, 4.5, NA)) + checkEquals(tmp2$f2.a, factor(c("M", NA, "M", NA, "M", NA, "F", NA, "F", NA))) + tmp2 <- wideByFactor(x=tmp, factor="f1", common=c("c1", "c2"), sort=TRUE, keepFactor=FALSE) + checkEquals(tmp2$f2.a, factor(c("M", "M", "M", "F", "F", NA, NA, NA, NA, NA))) + checkEquals(names(tmp2), c("c1", "c2", "y1.a", "y2.a", "f2.a", "y1.b", "y2.b", "f2.b")) +} + +### }}} +### {{{ Dear Emacs +## Local variables: +## folded-file: t +## End: +### }}} + +###------------------------------------------------------------------------ +### runit.wideByFactor.R ends here Copied: trunk/gdata/inst/unitTests/runit.write.fwf.R (from rev 1782, trunk/gdata/tests/runit.write.fwf.R) =================================================================== --- trunk/gdata/inst/unitTests/runit.write.fwf.R (rev 0) +++ trunk/gdata/inst/unitTests/runit.write.fwf.R 2014-04-05 02:23:45 UTC (rev 1784) @@ -0,0 +1,137 @@ +### runit.write.fwf.R +###------------------------------------------------------------------------ +### What: Unit tests for write.fwf +### $Id$ +### Time-stamp: <2008-08-05 11:58:50 ggorjan> +###------------------------------------------------------------------------ + +### {{{ --- Test setup --- + +if(FALSE) { + library("RUnit") + library("gdata") +} + +### }}} +### {{{ --- write.fwf --- + +test.write.fwf <- function() +{ + + ## 'x' must be a data.frame or matrix + checkException(write.fwf(1:10)) + checkException(write.fwf(list(1:10))) + + ## only single value is allowed in 'na' + checkException(write.fwf(data.frame(1:10, letters[1:10]), na=c("", " "))) + + ## Example dataset + num <- round(c(733070.345678, 1214213.78765456, 553823.798765678, + 1085022.8876545678, 571063.88765456, 606718.3876545678, + 1053686.6, 971024.187656, 631193.398765456, 879431.1), + digits=3) + + testData <- data.frame(num1=c(1:10, NA), + num2=c(NA, seq(from=1, to=5.5, by=0.5)), + num3=c(NA, num), + int1=c(as.integer(1:4), NA, as.integer(4:9)), + fac1=factor(c(NA, letters[1:9], "hjh")), + fac2=factor(c(letters[6:15], NA)), + cha1=c(letters[17:26], NA), + cha2=c(NA, "longer", letters[25:17]), + stringsAsFactors=FALSE) + levels(testData$fac1) <- c(levels(testData$fac1), "unusedLevel") + testData$Date <- as.Date("1900-1-1") + testData$Date[2] <- NA + testData$POSIXt <- as.POSIXct(strptime("1900-1-1 01:01:01", format="%Y-%m-%d %H:%M:%S")) + testData$POSIXt[5] <- NA + + ## --- output --- + ## is tested with regular tests + + ## --- formatInfo --- + + ## default output + formatInfoT <- data.frame(colname=c("num1", "num2"), + nlevels=c(0, 0), + position=c(1, 4), + width=c(2, 3), + digits=c(0, 1), + exp=c(0, 0), + stringsAsFactors=FALSE) + formatInfo <- write.fwf(testData[, c("num1", "num2")], formatInfo=TRUE) + checkEquals(formatInfo, formatInfoT) + + ## scientific notation + dd <- options("digits"); options(digits = 7) + testData2 <- data.frame(a=123, b=pi, c=1e8, d=1e222) + formatInfo <- write.fwf(x=testData2, formatInfo=TRUE) + checkEquals(formatInfo$width, c(3, 8, 5, 6)) + checkEquals(formatInfo$digits, c(0, 6, 0, 0)) + checkEquals(formatInfo$exp, c(0, 0, 2, 3)) + options(dd) ## reset old options + + ## 'na' can either decrease or increase the width + ## --> values of int1 have width 1 and using na="" should not increase + ## the width + formatInfo <- write.fwf(testData[, "int1", drop=FALSE], formatInfo=TRUE, + na="") + checkEquals(formatInfo$width, 1) + ## --> values of int1 have width 1 and using na="1234" should increase + ## the width to 4 + formatInfo <- write.fwf(testData... [truncated message content] |
From: <wa...@us...> - 2014-04-05 01:27:33
|
Revision: 1783 http://sourceforge.net/p/r-gregmisc/code/1783 Author: warnes Date: 2014-04-05 01:27:30 +0000 (Sat, 05 Apr 2014) Log Message: ----------- - For unit tests, don't check for equality of optional POSIXlt components. (Bug reported by Brian Ripley). Modified Paths: -------------- trunk/gdata/tests/runit.unknown.R Modified: trunk/gdata/tests/runit.unknown.R =================================================================== --- trunk/gdata/tests/runit.unknown.R 2014-04-05 01:08:30 UTC (rev 1782) +++ trunk/gdata/tests/runit.unknown.R 2014-04-05 01:27:30 UTC (rev 1783) @@ -7,11 +7,10 @@ ### {{{ --- Test setup --- -if(FALSE) { - library("RUnit") - library("gdata") -} +library("RUnit") +library("gdata") + ### {{{ --- Vectors --- intUnk <- 9999 @@ -332,9 +331,37 @@ ## Date-time classes checkIdentical(unknownToNA(xDateUnk, unknown=dateUnk), xDate) - checkIdentical(unknownToNA(xPOSIXltUnk, unknown=POSIXltUnk), xPOSIXlt) checkIdentical(unknownToNA(xPOSIXctUnk, unknown=POSIXctUnk), xPOSIXct) + ## Per Brian Ripley on 2014-01-15: + ## + ## On platforms where POSIXlt has a gmtoff component, it does not need to be set. So + ## + ## > z$gmtoff + ## [1] 3600 NA + ## > xPOSIXltUnk$gmtoff + ## [1] 3600 3600 + ## + ## (or sometimes 0, not NA). + ## + ## So although identical() correctly reports that they differ, this + ## is allowed for optional components. + ## + ## It would also be wrong to use identical() to compare isdst + ## components: isdst = -1 means unknown. + ## + tmp_unknownToNA <- unknownToNA(xPOSIXltUnk, unknown=POSIXltUnk) + tmp_xPOSIXlt <- xPOSIXlt + + tmp_unknownToNA$gmtoff <- NULL # Remove $gmtoff to avoid comparison + tmp_xPOSIXlt$gmtoff <- NULL + + tmp_unknownToNA$isdst <- NULL # Remove $isdst to avoid comparison + tmp_xPOSIXlt$isdst <- NULL + + checkIdentical(tmp_unknownToNA, tmp_xPOSIXlt) + + ## --- lists and data.frames --- ## with vector of single unknown values This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 01:08:34
|
Revision: 1782 http://sourceforge.net/p/r-gregmisc/code/1782 Author: warnes Date: 2014-04-05 01:08:30 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Move unit test code into the (now) standard location Added Paths: ----------- trunk/gdata/tests/Makefile trunk/gdata/tests/runRUnitTests.R trunk/gdata/tests/runit.bindData.R trunk/gdata/tests/runit.cbindX.R trunk/gdata/tests/runit.drop.levels.R trunk/gdata/tests/runit.getDateTimeParts.R trunk/gdata/tests/runit.mapLevels.R trunk/gdata/tests/runit.nPairs.R trunk/gdata/tests/runit.reorder.factor.R trunk/gdata/tests/runit.trim.R trunk/gdata/tests/runit.trimSum.R trunk/gdata/tests/runit.unknown.R trunk/gdata/tests/runit.wideByFactor.R trunk/gdata/tests/runit.write.fwf.R Removed Paths: ------------- trunk/gdata/R/runRUnitTests.R trunk/gdata/inst/unitTests/Makefile trunk/gdata/inst/unitTests/runRUnitTests.R trunk/gdata/inst/unitTests/runit.bindData.R trunk/gdata/inst/unitTests/runit.cbindX.R trunk/gdata/inst/unitTests/runit.drop.levels.R trunk/gdata/inst/unitTests/runit.getDateTimeParts.R trunk/gdata/inst/unitTests/runit.mapLevels.R trunk/gdata/inst/unitTests/runit.nPairs.R trunk/gdata/inst/unitTests/runit.reorder.factor.R trunk/gdata/inst/unitTests/runit.trim.R trunk/gdata/inst/unitTests/runit.trimSum.R trunk/gdata/inst/unitTests/runit.unknown.R trunk/gdata/inst/unitTests/runit.wideByFactor.R trunk/gdata/inst/unitTests/runit.write.fwf.R trunk/gdata/man/runRUnitTests.Rd Deleted: trunk/gdata/R/runRUnitTests.R =================================================================== --- trunk/gdata/R/runRUnitTests.R 2014-04-05 00:14:24 UTC (rev 1781) +++ trunk/gdata/R/runRUnitTests.R 2014-04-05 01:08:30 UTC (rev 1782) @@ -1,27 +0,0 @@ -### runRUnitTests.R -###------------------------------------------------------------------------ -### What: Run RUnit tests (wrapper function) - R code -### $Id$ -### Time-stamp: <2008-12-30 20:59:11 ggorjan> -###------------------------------------------------------------------------ - -.runRUnitTestsGdata <- function(testFileRegexp="^runit.+\\.[rR]$") -{ - ## Setup - .pkg <- environmentName(environment(.runRUnitTestsGdata)) - .path <- system.file("unitTests", package=.pkg) - .suite <- file.path(.path, "runRUnitTests.R") - - ## Some checks - stopifnot(file.exists(.path), - file.info(path.expand(.path))$isdir, - file.exists(.suite)) - - ## Run the suite - .way <- "function" - source(.suite, local=TRUE) - ## local=TRUE since .pkg and other vars do not exists in .suite environment -} - -###------------------------------------------------------------------------ -### runRUnitTests.R ends here Deleted: trunk/gdata/inst/unitTests/Makefile =================================================================== --- trunk/gdata/inst/unitTests/Makefile 2014-04-05 00:14:24 UTC (rev 1781) +++ trunk/gdata/inst/unitTests/Makefile 2014-04-05 01:08:30 UTC (rev 1782) @@ -1,22 +0,0 @@ -TOP=../.. -PKG=${shell cd ${TOP};pwd} -SUITE=runRUnitTests.R -R=R - -test: # Run unit tests - ${R} --vanilla --slave < ${SUITE} - -inst: # Install package - cd ${TOP}/..;\ - ${R} CMD INSTALL ${PKG} - -all: inst test - -echo: # Echo env. variables - @echo "Package folder: ${PKG}" - @echo "R binary: ${R}" - -help: # Help - @echo -e '\nTarget: Dependency # Description'; \ - echo '=================================================='; \ - egrep '^[[:alnum:].+_()%]*:' ./Makefile Deleted: trunk/gdata/inst/unitTests/runRUnitTests.R =================================================================== --- trunk/gdata/inst/unitTests/runRUnitTests.R 2014-04-05 00:14:24 UTC (rev 1781) +++ trunk/gdata/inst/unitTests/runRUnitTests.R 2014-04-05 01:08:30 UTC (rev 1782) @@ -1,104 +0,0 @@ -### runRUnitTests.R -###------------------------------------------------------------------------ -### What: Run RUnit tests (the core)- R code -### $Id$ -### Time-stamp: <2008-12-30 12:52:51 ggorjan> -###------------------------------------------------------------------------ - -## The setup seems to be quite messy, but it is so to enable use of this in -## several ways as shown bellow. - -## "R CMD check" way should be the most authoritative way to run the RUnit -## tests for a developer. RUnit tests are issued during R CMD check of the -## package due to example section of .runRUnitTests() function. If any test -## fails (failure) or if there are any R errors during RUnit testing, R CMD -## check fails. These are variable values specific for this way: -## - .path DEVEL/PATH/PKG.Rcheck/PKG/unitTests -## - .way function - -## ".runRUnitTests()" way from within R after library(PKG) is handy for -## package useRs, since it enables useRs to be sure that all tests pass for -## their installation. This is just a convenient wrapper function to run -## the RUnit testing suite. These are variable values specific for this -## way: -## - .path INSTALL/PATH/PKG/unitTests -## - .way function - -## "Shell" way is another possibility mainly for a developer in order to -## skip possibly lengthy R CMD check and perform just RUnit testing with an -## installed version of a pcakage. These are variable values specific for -## this way: -## - .path DEVEL/PATH/PKG/inst/unitTests -## - .way shell -## -## Rscript runRUnitTests.R -## R CMD BATCH runRUnitTests.R -## make -## make all - -## Sourced via shell (Makefile, Rscript, R CMD BATCH) -if(!exists(".pkg")) { - .path <- getwd() - .way <- "shell" - .pkg <- c(read.dcf(file="../../DESCRIPTION", fields="Package")) - print(.pkg) - testFileRegexp <- "^base.+\\.[rR]$" -} - -if(require("RUnit", quietly=TRUE)) { - - ## Debugging echo - cat("\nRunning RUnit tests\n") - print(list(pkg=.pkg, getwd=getwd(), pathToRUnitTests=.path)) - - ## Load the package - not needed for .runRUnitTests() - if(.way %in% c("shell")) - library(package=.pkg, character.only=TRUE) - - ## Define tests - testSuite <- defineTestSuite(name=paste(.pkg, "RUnit testing"), - dirs=.path, testFileRegexp=testFileRegexp) - - ## Run - tests <- runTestSuite(testSuite) - - if(file.access(.path, 02) != 0) { - ## cannot write to .path -> use writable one - tdir <- tempfile(paste(.pkg, "RUnitTests", sep="_")) - dir.create(tdir) - pathReport <- file.path(tdir, "report") - } else { - pathReport <- file.path(.path, "report") - } - - ## Print results: - printTextProtocol(tests) - printTextProtocol(tests, - fileName=paste(pathReport, ".txt", sep="")) - - ## Print HTML Version of results: - printHTMLProtocol(tests, - fileName=paste(pathReport, ".html", sep="")) - - cat("\nRUnit reports also written to\n", - pathReport, ".(txt|html)\n\n", sep="") - - ## Return stop() to cause R CMD check stop in case of - ## - failures i.e. FALSE to RUnit tests or - ## - errors i.e. R errors - tmp <- getErrors(tests) - if(tmp$nFail > 0 || tmp$nErr > 0) { - stop(paste("\n\nRUnit testing failed:\n", - " - #test failures: ", tmp$nFail, "\n", - " - #R errors: ", tmp$nErr, "\n\n", sep="")) - } - -} else { - - cat("R package 'RUnit' cannot be loaded - no unit tests run\n", - "for package", .pkg,"\n") - -} - -###------------------------------------------------------------------------ -### runRUnitTests.R ends here Deleted: trunk/gdata/inst/unitTests/runit.bindData.R =================================================================== --- trunk/gdata/inst/unitTests/runit.bindData.R 2014-04-05 00:14:24 UTC (rev 1781) +++ trunk/gdata/inst/unitTests/runit.bindData.R 2014-04-05 01:08:30 UTC (rev 1782) @@ -1,75 +0,0 @@ -### runit.bindData.R -###------------------------------------------------------------------------ -### What: Bind two data frames - unit tests -### $Id$ -### Time-stamp: <2008-12-30 11:58:50 ggorjan> -###------------------------------------------------------------------------ - -### {{{ --- Test setup --- - -if(FALSE) { - library("RUnit") - library("gdata") -} - -### }}} -### {{{ --- bindData --- - -test.bindData <- function() -{ - ## 'x'/'y' must be a data.frame - checkException(bindData(x=1:10, y=1:10)) - checkException(bindData(x=matrix(1:10), y=matrix(1:10))) - - n1 <- 6; n2 <- 12; n3 <- 4 - ## Single trait 1 - num <- c(5:n1, 10:13) - tmp1 <- data.frame(y1=rnorm(n=n1), - f1=factor(rep(c("A", "B"), n1/2)), - ch=letters[num], - fa=factor(letters[num]), - nu=(num) + 0.5, - id=factor(num), stringsAsFactors=FALSE) - - ## Single trait 2 with repeated records, some subjects also in tmp1 - num <- 4:9 - tmp2 <- data.frame(y2=rnorm(n=n2), - f2=factor(rep(c("C", "D"), n2/2)), - ch=letters[rep(num, times=2)], - fa=factor(letters[rep(c(num), times=2)]), - nu=c((num) + 0.5, (num) + 0.25), - id=factor(rep(num, times=2)), stringsAsFactors=FALSE) - - ## Single trait 3 with completely distinct set of subjects - num <- 1:4 - tmp3 <- data.frame(y3=rnorm(n=n3), - f3=factor(rep(c("E", "F"), n3/2)), - ch=letters[num], - fa=factor(letters[num]), - nu=(num) + 0.5, - id=factor(num), stringsAsFactors=FALSE) - - ## Combine all datasets - tmp12 <- bindData(x=tmp1, y=tmp2, common=c("id", "nu", "ch", "fa")) - tmp123 <- bindData(x=tmp12, y=tmp3, common=c("id", "nu", "ch", "fa")) - - checkEquals(names(tmp123), c("id", "nu", "ch", "fa", "y1", "f1", "y2", "f2", "y3", "f3")) - checkEquals(rbind(tmp1["id"], tmp2["id"], tmp3["id"]), tmp123["id"]) - checkEquals(rbind(tmp1["fa"], tmp2["fa"], tmp3["fa"]), tmp123["fa"]) - checkEquals(is.na(tmp123$y1), c(rep(FALSE, times=n1), rep(TRUE, times=n2+n3))) - checkEquals(is.na(tmp123$f1), c(rep(FALSE, times=n1), rep(TRUE, times=n2+n3))) - checkEquals(is.na(tmp123$y2), c(rep(TRUE, times=n1), rep(FALSE, times=n2), rep(TRUE, times=n3))) - checkEquals(is.na(tmp123$f2), c(rep(TRUE, times=n1), rep(FALSE, times=n2), rep(TRUE, times=n3))) - checkEquals(is.na(tmp123$y3), c(rep(TRUE, times=n1+n2), rep(FALSE, times=n3))) - checkEquals(is.na(tmp123$f3), c(rep(TRUE, times=n1+n2), rep(FALSE, times=n3))) -} - -### }}} -### {{{ Dear Emacs -## Local variables: -## folded-file: t -## End: -### }}} - -###------------------------------------------------------------------------ -### runit.bindData.R ends here Deleted: trunk/gdata/inst/unitTests/runit.cbindX.R =================================================================== --- trunk/gdata/inst/unitTests/runit.cbindX.R 2014-04-05 00:14:24 UTC (rev 1781) +++ trunk/gdata/inst/unitTests/runit.cbindX.R 2014-04-05 01:08:30 UTC (rev 1782) @@ -1,81 +0,0 @@ -### runit.cbindX.R -###------------------------------------------------------------------------ -### What: Unit tests for cbindX -### $Id:$ -### Time-stamp: <2008-08-05 13:40:49 ggorjan> -###------------------------------------------------------------------------ - -### {{{ --- Test setup --- - -if(FALSE) { - library("RUnit") - library("gdata") -} - -### }}} -### {{{ --- cbindX --- - -test.cbindX <- function() -{ - df1 <- data.frame(a=1:3, b=c("A", "B", "C")) - df2 <- data.frame(c=as.character(1:5), a=5:1) - - ma1 <- matrix(as.character(1:4), nrow=2, ncol=2) - ma2 <- matrix(1:6, nrow=3, ncol=2) - - df12test <- cbindX(df1, df2) - df12stand <- data.frame(a=c(1:3, NA, NA), - b=c("A", "B", "C", NA, NA), - c=as.character(1:5), - a=5:1) - names(df12stand)[4] <- "a" - checkEquals(df12test, df12stand) - - ma12test <- cbindX(ma1, ma2) - ma12stand <- matrix(as.character(c(1, 3, 1, 4, - 2, 4, 2, 5, - NA, NA, 3, 6)), nrow=3, ncol=4, byrow=TRUE) - checkEquals(ma12test, ma12stand) - - da11test <- cbindX(df1, ma1) - da11stand <- data.frame(a=1:3, - b=c("A", "B", "C"), - as.character(c(1:2, NA)), - as.character(c(3:4, NA))) - names(da11stand)[3:4] <- c("1", "2") - checkEquals(da11test, da11stand) - - tmpTest <- cbindX(df1, df2, ma1, ma2) - tmpStand <- data.frame(a=c(1:3, NA, NA), - b=c("A", "B", "C", NA, NA), - c=as.character(1:5), - a=5:1, - as.character(c(1:2, NA, NA, NA)), - as.character(c(3:4, NA, NA, NA)), - c(1:3, NA, NA), - c(4:6, NA, NA)) - names(tmpStand)[4:8] <- c("a", "1", "2", "1", "2") - checkEquals(tmpTest, tmpStand) - - tmpTest <- cbindX(ma1, ma2, df1, df2) - tmpStand <- data.frame(as.character(c(1:2, NA, NA, NA)), - as.character(c(3:4, NA, NA, NA)), - as.character(c(1:3, NA, NA)), - as.character(c(4:6, NA, NA)), - a=c(1:3, NA, NA), - b=c("A", "B", "C", NA, NA), - c=as.character(1:5), - a=5:1) - names(tmpStand)[c(1:4, 8)] <- c("1", "2", "3", "4", "a") - checkEquals(tmpTest, tmpStand) -} - -### }}} -### {{{ Dear Emacs -### Local variables: -### folded-file: t -### end: -### }}} - -###------------------------------------------------------------------------ -### runit.cbindX.R ends here Deleted: trunk/gdata/inst/unitTests/runit.drop.levels.R =================================================================== --- trunk/gdata/inst/unitTests/runit.drop.levels.R 2014-04-05 00:14:24 UTC (rev 1781) +++ trunk/gdata/inst/unitTests/runit.drop.levels.R 2014-04-05 01:08:30 UTC (rev 1782) @@ -1,42 +0,0 @@ -### runit.drop.levels.R -###------------------------------------------------------------------------ -### What: Tests for drop.levels -### $Id$ -### Time-stamp: <2006-08-29 14:21:12 ggorjan> -###------------------------------------------------------------------------ - -### {{{ --- Test setup --- - -if(FALSE) { - library("RUnit") - library("gdata") -} - -### }}} -### {{{ --- drop.levels --- - -test.drop.levels <- function() -{ - f <- factor(c("A", "B", "C", "D"))[1:3] - fDrop <- factor(c("A", "B", "C")) - - l <- list(f=f, i=1:3, c=c("A", "B", "D")) - lDrop <- list(f=fDrop, i=1:3, c=c("A", "B", "D")) - - df <- as.data.frame(l) - dfDrop <- as.data.frame(lDrop) - - checkIdentical(drop.levels(f), fDrop) - checkIdentical(drop.levels(l), lDrop) - checkIdentical(drop.levels(df), dfDrop) -} - -### }}} -### {{{ Dear Emacs -## Local variables: -## folded-file: t -## End: -### }}} - -###------------------------------------------------------------------------ -### runit.drop.levels.R ends here Deleted: trunk/gdata/inst/unitTests/runit.getDateTimeParts.R =================================================================== --- trunk/gdata/inst/unitTests/runit.getDateTimeParts.R 2014-04-05 00:14:24 UTC (rev 1781) +++ trunk/gdata/inst/unitTests/runit.getDateTimeParts.R 2014-04-05 01:08:30 UTC (rev 1782) @@ -1,119 +0,0 @@ -### runit.getDateTimeParts.R -###------------------------------------------------------------------------ -### What: Extract date and time parts from ... - unit tests -### $Id$ -### Time-stamp: <2008-12-30 22:41:18 ggorjan> -###------------------------------------------------------------------------ - -### {{{ --- Test setup --- - -if(FALSE) { - library("RUnit") - library("gdata") -} - -num <- 1 -cha <- "a" -fac <- factor(c("A")) - -tYear <- as.character(c(2006, 1995, 1005, 3067)) -tMonth <- c("01", "04", "06", "12") -tDay <- c("01", "12", "22", "04") -tDate <- paste( paste(tYear, tMonth, tDay, sep="-"), "GMT" ) - -tHour <- c("05", "16", "20", "03") -tMin <- c("16", "40", "06", "52") -tSec <- c("56", "34", "05", "15") -tTime <- paste(tHour, tMin, tSec, sep=":") - -cDate <- as.Date(tDate) -cDatePOSIXct <- as.POSIXct(tDate) -cDatePOSIXlt <- as.POSIXlt(tDate) - -### }}} -### {{{ --- getYear --- - -test.getYear <- function() -{ - checkException(getYear(x=num)) - checkException(getYear(x=cha)) - checkException(getYear(x=fac)) - - checkIdentical(getYear(x=cDate), tYear) - checkIdentical(getYear(x=cDatePOSIXct), tYear) - checkIdentical(getYear(x=cDatePOSIXlt), tYear) -} - -### }}} -### {{{ --- getMonth --- - -test.getMonth <- function() -{ - checkException(getMonth(x=num)) - checkException(getMonth(x=cha)) - checkException(getMonth(x=fac)) - - checkIdentical(getMonth(x=cDate), tMonth) - checkIdentical(getMonth(x=cDatePOSIXct), tMonth) - checkIdentical(getMonth(x=cDatePOSIXlt), tMonth) -} - -### }}} -### {{{ --- getDay --- - -test.getDay <- function() -{ - checkException(getDay(x=num)) - checkException(getDay(x=cha)) - checkException(getDay(x=fac)) - - checkIdentical(getDay(x=cDate), tDay) - checkIdentical(getDay(x=cDatePOSIXct), tDay) - checkIdentical(getDay(x=cDatePOSIXlt), tDay) -} - -### }}} -### {{{ --- getHour --- - -test.getHour <- function() -{ - checkException(getHour(x=num)) - checkException(getHour(x=cha)) - checkException(getHour(x=fac)) - -## checkIdentical(getHour(x=cDate), tHour) -} - -### }}} -### {{{ --- getMin --- - -test.getMin <- function() -{ - checkException(getMin(x=num)) - checkException(getMin(x=cha)) - checkException(getMin(x=fac)) - -## checkIdentical(getMin(x=cDate), tMin) -} - -### }}} -### {{{ --- getSec --- - -test.getSec <- function() -{ - checkException(getSec(x=num)) - checkException(getSec(x=cha)) - checkException(getSec(x=fac)) - -## checkIdentical(getSec(x=cDate), tSec) -} - -### }}} -### {{{ Dear Emacs -### Local variables: -### folded-file: t -### end: -### }}} - -###------------------------------------------------------------------------ -### runit.getDateTimeParts.R ends here Deleted: trunk/gdata/inst/unitTests/runit.mapLevels.R =================================================================== --- trunk/gdata/inst/unitTests/runit.mapLevels.R 2014-04-05 00:14:24 UTC (rev 1781) +++ trunk/gdata/inst/unitTests/runit.mapLevels.R 2014-04-05 01:08:30 UTC (rev 1782) @@ -1,281 +0,0 @@ -### runit.mapLevels.R -###------------------------------------------------------------------------ -### What: Unit tests for mapLevels et al. -### $Id$ -### Time-stamp: <2006-10-29 16:41:41 ggorjan> -###------------------------------------------------------------------------ - -### {{{ --- Test setup --- - -if(FALSE) { - library("RUnit") - library("gdata") -} - -### }}} -### {{{ mapLevels, is.*, as.*, [.* - -test.mapLevels <- function() -{ - ## Integer and numeric - checkException(mapLevels(1:3)) # wrong class(x) - checkException(mapLevels(1.5)) # wrong class(x) - - ## Factor - f <- factor(c("B", "C", "A")) - fMapInt <- list(A=as.integer(1), B=as.integer(2), C=as.integer(3)) - fMapInt1 <- list(B=as.integer(1), C=as.integer(2)) - fMapCha <- list(A="A", B="B", C="C") - fMapInt <- as.levelsMap(fMapInt) - fMapInt1 <- as.levelsMap(fMapInt1) - fMapCha <- as.levelsMap(fMapCha) - fMapCha1 <- fMapCha[c(1, 3)] # this will test also [.levelsMap - checkIdentical(mapLevels(f), fMapInt) - checkTrue(is.levelsMap(mapLevels(f))) # test for is.levelsMap - checkTrue(is.levelsMap(fMapInt)) # test for as.levelsMap - checkTrue(!gdata:::.isCharacterMap(fMapInt)) - checkIdentical(mapLevels(f, sort=FALSE), fMapInt) # sort is not used for factors - checkIdentical(mapLevels(f[1:2], drop=TRUE), fMapInt1) - checkIdentical(mapLevels(f, codes=FALSE), fMapCha) - checkIdentical(mapLevels(f[c(2, 3)], drop=TRUE, codes=FALSE), fMapCha1) - - ## Character - cha <- c("Z", "M", "A") - chaMapInt <- list(A=as.integer(1), M=as.integer(2), Z=as.integer(3)) - chaMapIntO <- list(Z=as.integer(1), M=as.integer(2), A=as.integer(3)) - chaMapInt1 <- list(M=as.integer(1), Z=as.integer(2)) - chaMapCha <- list(A="A", M="M", Z="Z") - chaMapInt <- as.levelsMap(chaMapInt) - chaMapIntO <- as.levelsMap(chaMapIntO) - chaMapInt1 <- as.levelsMap(chaMapInt1) - chaMapCha <- as.levelsMap(chaMapCha) - checkIdentical(mapLevels(cha), chaMapInt) - checkIdentical(mapLevels(cha, sort=FALSE), chaMapIntO) # sort works for characters - checkIdentical(mapLevels(cha[1:2], drop=TRUE), chaMapInt1) - checkIdentical(mapLevels(cha, codes=FALSE), chaMapCha) - - ## List - l <- list(f=f, cha=cha) - l1 <- list(cha=cha, f=f) - l2 <- list(cha=cha, f=f, i=1:10) - lMapInt <- list(f=fMapInt, cha=chaMapInt) - lMapCha <- list(f=fMapCha, cha=chaMapCha) - lMapInt <- as.listLevelsMap(lMapInt) - lMapCha <- as.listLevelsMap(lMapCha) - lMapChaC <- as.list(sort(unique(c(cha, as.character(f))))) - lMapChaCO <- as.list(unique(c(cha, as.character(f)))) - names(lMapChaC) <- unlist(lMapChaC) - names(lMapChaCO) <- unlist(lMapChaCO) - lMapChaC <- as.levelsMap(lMapChaC) - lMapChaCO <- as.levelsMap(lMapChaCO) - checkIdentical(mapLevels(l), lMapInt) - checkTrue(is.listLevelsMap(mapLevels(l))) # test for is.listLevelsMap - checkTrue(is.listLevelsMap(lMapInt)) # test for as.listLevelsMap - checkIdentical(mapLevels(l, codes=FALSE), lMapCha) - checkException(mapLevels(l, combine=TRUE)) # can not combine integer maps - checkIdentical(mapLevels(l, codes=FALSE, combine=TRUE), lMapChaC) - checkIdentical(mapLevels(l1, codes=FALSE, combine=TRUE), lMapChaC) - checkIdentical(mapLevels(l1, codes=FALSE, combine=TRUE, sort=FALSE), lMapChaCO) - checkException(mapLevels(l2)) # only char and factor - - ## Data.frame - df <- data.frame(f1=factor(c("G", "Abc", "Abc", "D", "F")), - f2=factor(c("Abc", "Abc", "B", "D", "K")), - cha=c("jkl", "A", "D", "K", "L"), - int=1:5) - dfMapInt <- list(f1=mapLevels(df$f1), f2=mapLevels(df$f2), cha=mapLevels(df$cha)) - dfMapInt <- as.listLevelsMap(dfMapInt) - dfMapInt1 <- dfMapInt[c(1, 3)] # this will test also [.listLevelsMap - checkException(mapLevels(df)) # wrong class of int - checkIdentical(mapLevels(df[, 1:3]), dfMapInt) - checkIdentical(mapLevels(df[, c(1, 3)]), dfMapInt1) -} - -### }}} -### {{{ .check* - -test.checkLevelsMap <- function(x) -{ - ## --- levelsMap --- - - ## not a list - checkException(gdata:::.checkLevelsMap(x="A", method="raw")) - ## list without names - checkException(gdata:::.checkLevelsMap(x=list("A"), method="raw")) - fMapInt <- list(A=as.integer(1), B=as.integer(2), C=as.integer(3)) - ## x should be levelsMap - checkException(gdata:::.checkLevelsMap(x=fMapInt, method="class")) - - ## --- listLevelsMap --- - - map <- list(as.levelsMap(fMapInt), as.levelsMap(fMapInt)) - map1 <- list(fMapInt, fMapInt) - class(map1) <- "listLevelsMap" - ## x should be a listLevelsMap - checkException(gdata:::.checkListLevelsMap(x=map, method="class")) - ## x should be also a list of levelsMaps - checkException(gdata:::.checkListLevelsMap(x=map1, method="class")) - ## the rest is done with levelsMap tests -} - -### }}} -### {{{ c.* - -test.cLevelsMap <- function() -{ - f1 <- factor(letters[c(2, 1)]) - f2 <- factor(letters[c(3, 1, 2)]) - mapCha1 <- mapLevels(f1, codes=FALSE) # get maps - mapCha2 <- mapLevels(f2, codes=FALSE) - mapCha1S <- mapLevels(as.character(f1), codes=FALSE, sort=FALSE) - mapCha2S <- mapLevels(as.character(f2), codes=FALSE, sort=FALSE) - mapChaTest <- list(a="a", b="b") - mapChaTest1 <- list(a="a", b="b", c="c") - mapChaTest2 <- list(c="c", a="a", b="b") - class(mapChaTest) <- class(mapChaTest1) <- class(mapChaTest2) <- "levelsMap" - mapChaTest3 <- list(mapChaTest, mapChaTest1, mapChaTest, mapChaTest1) - class(mapChaTest3) <- "listLevelsMap" - checkIdentical(c(mapCha1), mapChaTest) - checkIdentical(c(mapCha2, mapCha1), mapChaTest1) - checkIdentical(c(mapCha2S, mapCha1S, sort=FALSE), mapChaTest2) - - l <- list(f1, f2) - mapCha <- mapLevels(l, codes=FALSE) - checkIdentical(c(mapCha, mapCha), mapChaTest3) - checkIdentical(c(mapCha, recursive=TRUE), mapChaTest1) - - checkException(c(mapLevels(f1))) # can not combine integer “levelsMaps” - - ## Example with maps of different length of components - map1 <- list(A=c("a", "e", "i", "o", "u"), B="b", C="c", C="m", - D=c("d", "e"), F="f") - map2 <- list(A=c("a", "z", "w", "y", "x"), F="f", G=c("g", "h", "j"), - i="i", k=c("k", "l"), B="B") - map0Test <- list(A=c("a", "e", "i", "o", "u"), B="b", C="c", C="m", - D=c("d", "e"), F="f", - A=c("z", "w", "y", "x"), G=c("g", "h", "j"), - i="i", k=c("k", "l"), B="B") - map0Test <- as.levelsMap(map0Test) - mapTest <- sort(map0Test) - map1 <- as.levelsMap(map1) - map2 <- as.levelsMap(map2) - map <- c(map1, map2) - map0 <- c(map1, map2, sort=FALSE) - checkIdentical(map, mapTest) - checkIdentical(map0, map0Test) -} - -### }}} -### {{{ unique - -test.uniqueLevelsMap <- function() -{ - map <- list(A=c(1, 2, 1, 3), B=4, C=1, C=5, D=c(6, 8), E=7, B=4, - D=c(6, 8)) - map1 <- map - map1[[1]] <- map[[1]][c(1, 2, 4)] - map1[[7]] <- NULL # remove B=4 - map1[[7]] <- NULL # remove D=c(6, 8) - ## unique (used in as.levelsMap), will remove duplicates (A=1) - checkIdentical(as.levelsMap(map1), as.levelsMap(map)) -} - -### }}} -### {{{ mapLevels<- - -"test.mapLevels<-" <- function() -{ - ## Some errors - checkException("mapLevels<-"(1.1, value=2)) # wrong class(x) - checkException("mapLevels<-"(complex(1.1), value=2)) # wrong class(x) - - f <- factor(c("A", "B", "C")) - fMapInt <- mapLevels(f) - ## can not apply integer "levelsMap" to "character" - checkException("mapLevels<-"(as.character(f), value=fMapInt)) - - fMapCha <- mapLevels(f, codes=FALSE) - ## can not apply character levelsMap to "integer" - checkException("mapLevels<-"(as.integer(f), value=chaMapCha)) - - fMapFuzz <- fMapInt - fMapFuzz[[1]] <- "A" - ## all components of 'value' must be of the same class - checkException("mapLevels<-"(as.character(f), value=fMapFuzz)) - checkException("mapLevels<-"(as.integer(f), value=fMapFuzz)) - - ## x integer, value integer levelsMap - f <- factor(letters[c(10, 15, 1, 2)]) - fMapInt <- mapLevels(f) - fInt <- as.integer(f) - mapLevels(fInt) <- fMapInt - checkIdentical(fInt, f) - - ## x factor, value integer levelsMap - fInt <- factor(as.integer(f)) - mapLevels(fInt) <- fMapInt - checkIdentical(fInt, f) - - ## above is essentially the same as levels<-.factor - fInt1 <- factor(as.integer(f)) - levels(fInt1) <- fMapInt - checkIdentical(fInt1, f) - - ## x character, value character levelsMap - cha <- c("B", "A", "C") - chaMapCha <- as.levelsMap(list(A1="A", B2="B", C3="C")) - mapLevels(cha) <- chaMapCha - chaTest <- factor(c("B2", "A1", "C3")) - checkIdentical(cha, chaTest) - ## and a bit more for components of length > 1 - cha <- c("G", "I", "B", "A", "C", "D", "Z") - chaMapCha <- as.levelsMap(list(A1=c("A", "G", "I"), B2="B", C3=c("C", "D"))) - mapLevels(cha) <- chaMapCha - chaTest <- factor(c("A1", "A1", "B2", "A1", "C3", "C3", NA)) - checkIdentical(cha, chaTest) - - ## x factor, value character levelsMap - f <- factor(c("G", "I", "B", "A", "C", "D", "Z")) - fMapCha <- as.levelsMap(list(A1=c("A", "G", "I"), B2="B", C3=c("C", "D"))) - mapLevels(f) <- fMapCha - fTest <- factor(c("A1", "A1", "B2", "A1", "C3", "C3", NA)) - checkIdentical(f, fTest) - - ## Two factors and character map - f1 <- factor(letters[1:10]) - f2 <- factor(letters[5:14]) - checkIdentical(as.integer(f1), as.integer(f2)) # the same integer codes - mapCha1 <- mapLevels(f1, codes=FALSE) # get maps - mapCha2 <- mapLevels(f2, codes=FALSE) - mapCha <- c(mapCha1, mapCha2) # combine maps - ## apply map - mapLevels(f1) <- mapCha # the same as levels(f1) <- mapCha - mapLevels(f2) <- mapCha # the same as levels(f2) <- mapCha - checkIdentical(as.integer(f1), 1:10) # \ internal codes are now - checkIdentical(as.integer(f2), 5:14) # / "consistent" among factors - - ## The same with list - l <- list(f1=f1, f2=f2) - mapCha <- mapLevels(l, codes=FALSE, combine=TRUE) - mapLevels(l) <- mapCha - checkIdentical(as.integer(l$f1), 1:10) # \ internal codes are now - checkIdentical(as.integer(l$f2), 5:14) # / "consistent" among factors - - ## and data.frame - df <- data.frame(f1=f1, f2=f2) - mapCha <- mapLevels(df, codes=FALSE, combine=TRUE) - mapLevels(df) <- mapCha - checkIdentical(as.integer(df$f1), 1:10) # \ internal codes are now - checkIdentical(as.integer(df$f2), 5:14) # / "consistent" among factors - -} - -### }}} -### {{{ Dear Emacs -## Local variables: -## folded-file: t -## End: -### }}} - -###------------------------------------------------------------------------ -### runit.mapLevels.R ends here Deleted: trunk/gdata/inst/unitTests/runit.nPairs.R =================================================================== --- trunk/gdata/inst/unitTests/runit.nPairs.R 2014-04-05 00:14:24 UTC (rev 1781) +++ trunk/gdata/inst/unitTests/runit.nPairs.R 2014-04-05 01:08:30 UTC (rev 1782) @@ -1,68 +0,0 @@ -### runit.nPairs.R -###------------------------------------------------------------------------ -### What: Number of variable pairs - unit tests -### $Id$ -### Time-stamp: <2008-12-30 18:24:59 ggorjan> -###------------------------------------------------------------------------ - -### {{{ --- Test setup --- - -if(FALSE) { - library("RUnit") - library("gdata") -} - -### }}} -### {{{ --- nPairs --- - -test.nPairs <- function() -{ - ## 'x' must be a data.frame or a matrix - x <- rpois(100, lambda=10) - checkException(nPairs(x=x)) - checkException(nPairs(x=table(x))) - - test <- data.frame(V1=c(1, 2, 3, 4, 5), - V2=c(NA, 2, 3, 4, 5), - V3=c(1, NA, NA, NA, NA), - V4=c(1, 2, 3, NA, NA)) - testCheck <- matrix(data=as.integer(c(5, 4, 1, 3, - 4, 4, 0, 2, - 1, 0, 1, 1, - 3, 2, 1, 3)), - nrow=4, ncol=4, byrow=TRUE) - class(testCheck) <- c("nPairs", class(testCheck)) - - testCheckNames <- testCheck - colnames(testCheckNames) <- rownames(testCheckNames) <- colnames(test) - - checkIdentical(nPairs(x=test), testCheckNames) - checkIdentical(nPairs(x=test, names=FALSE), testCheck) - checkIdentical(nPairs(x=as.matrix(test)), testCheckNames) - checkIdentical(nPairs(x=as.matrix(test), names=FALSE), testCheck) - - testCheck <- cbind(testCheckNames, as.integer(c(5, 4, 0, 0))) - class(testCheck) <- class(testCheckNames) - colnames(testCheck) <- c(colnames(test), "all") - checkIdentical(nPairs(x=test, margin=TRUE), testCheck) - - testCheckSumm <- matrix(data=as.integer(c(0, 1, 4, 2, - 0, 0, 4, 2, - 0, 1, 0, 0, - 0, 1, 2, 0)), - nrow=4, ncol=4, byrow=TRUE) - dimnames(testCheckSumm) <- dimnames(testCheckNames) - tmp <- summary(nPairs(x=test)) - checkEquals(tmp, testCheckSumm) -} - - -### }}} -### {{{ Dear Emacs -### Local variables: -### folded-file: t -### end: -### }}} - -###------------------------------------------------------------------------ -### runit.nPairs.R ends here Deleted: trunk/gdata/inst/unitTests/runit.reorder.factor.R =================================================================== --- trunk/gdata/inst/unitTests/runit.reorder.factor.R 2014-04-05 00:14:24 UTC (rev 1781) +++ trunk/gdata/inst/unitTests/runit.reorder.factor.R 2014-04-05 01:08:30 UTC (rev 1782) @@ -1,64 +0,0 @@ -### runit.reorder.factor.R -###------------------------------------------------------------------------ -### What: Tests for reorder.factor -### $Id$ -### Time-stamp: <2006-10-30 18:25:05 ggorjan> -###------------------------------------------------------------------------ - -### {{{ --- Test setup --- - -if(FALSE) { - library("RUnit") - library("gdata") -} - -### }}} -### {{{ --- reorder.factor --- - -test.reorder.factor <- function() -{ - tmp <- Sys.getlocale(category="LC_COLLATE") - Sys.setlocale(category="LC_COLLATE", locale="C") - - ## Create a 4 level example factor - levs <- c("PLACEBO", "300 MG", "600 MG", "1200 MG") - trt <- factor(rep(x=levs, times=c(22, 24, 28, 26))) - - ## Change the order to something useful - ## default "mixedsort" ordering - trt2 <- reorder(trt) - levsTest <- c("300 MG", "600 MG", "1200 MG", "PLACEBO") - checkIdentical(levels(trt2), levsTest) - - ## using indexes: - trt3 <- reorder(trt, new.order=c(4, 2, 3, 1)) - levsTest <- c("PLACEBO", "300 MG", "600 MG", "1200 MG") - checkIdentical(levels(trt3), levsTest) - - ## using label names: - trt4 <- reorder(trt, new.order=c("PLACEBO", "300 MG", "600 MG", "1200 MG")) - levsTest <- c("PLACEBO", "300 MG", "600 MG", "1200 MG") - checkIdentical(levels(trt4), levsTest) - - ## using frequency - trt5 <- reorder(trt, X=as.numeric(trt), FUN=length) - levsTest <- c("PLACEBO", "300 MG", "1200 MG", "600 MG") - checkIdentical(levels(trt5), levsTest) - - ## drop out the '300 MG' level - trt6 <- reorder(trt, new.order=c("PLACEBO", "600 MG", "1200 MG")) - levsTest <- c("PLACEBO", "600 MG", "1200 MG") - checkIdentical(levels(trt6), levsTest) - - Sys.setlocale(category="LC_COLLATE", locale=tmp) -} - -### }}} -### {{{ Dear Emacs -## Local variables: -## folded-file: t -## End: -### }}} - -###------------------------------------------------------------------------ -### runit.reorder.factor.R ends here Deleted: trunk/gdata/inst/unitTests/runit.trim.R =================================================================== --- trunk/gdata/inst/unitTests/runit.trim.R 2014-04-05 00:14:24 UTC (rev 1781) +++ trunk/gdata/inst/unitTests/runit.trim.R 2014-04-05 01:08:30 UTC (rev 1782) @@ -1,55 +0,0 @@ -### runit.trim.R -###------------------------------------------------------------------------ -### What: Tests for trim -### $Id$ -### Time-stamp: <2006-08-29 14:21:02 ggorjan> -###------------------------------------------------------------------------ - -### {{{ --- Test setup --- - -if(FALSE) { - library("RUnit") - library("gdata") -} - -### }}} -### {{{ --- trim --- - -test.trim <- function() -{ - tmp <- Sys.getlocale(category="LC_COLLATE") - Sys.setlocale(category="LC_COLLATE", locale="C") - - sTrim <- " this is an example string " - sTrimR <- "this is an example string" - - fTrim <- factor(c(sTrim, sTrim, " A", " B ", " C ", "D ")) - fTrimR <- factor(c(sTrimR, sTrimR, "A", "B", "C", "D")) - - lTrim <- list(s=rep(sTrim, times=6), f=fTrim, i=1:6) - lTrimR <- list(s=rep(sTrimR, times=6), f=fTrimR, i=1:6) - - dfTrim <- as.data.frame(lTrim) - dfTrimR <- as.data.frame(lTrimR) - - checkIdentical(trim(sTrim), sTrimR) - checkIdentical(trim(fTrim), fTrimR) - checkIdentical( - levels(trim(fTrim, recode.factor=FALSE)), - c("this is an example string", "C", "A", "B", "D") - ) - checkIdentical(trim(lTrim), lTrimR) - checkIdentical(trim(dfTrim), dfTrimR) - - Sys.setlocale(category="LC_COLLATE", locale=tmp) -} - -### }}} -### {{{ Dear Emacs -## Local variables: -## folded-file: t -## End: -### }}} - -###------------------------------------------------------------------------ -### runit.trim.R ends here Deleted: trunk/gdata/inst/unitTests/runit.trimSum.R =================================================================== --- trunk/gdata/inst/unitTests/runit.trimSum.R 2014-04-05 00:14:24 UTC (rev 1781) +++ trunk/gdata/inst/unitTests/runit.trimSum.R 2014-04-05 01:08:30 UTC (rev 1782) @@ -1,61 +0,0 @@ -### runit.trimSum.R -###------------------------------------------------------------------------ -### What: Unit tests for trimSum -### $Id$ -### Time-stamp: <2008-12-20 11:58:50 ggorjan> -###------------------------------------------------------------------------ - -### {{{ --- Test setup --- - -if(FALSE) { - library("RUnit") - library("gdata") -} - -### }}} -### {{{ --- trimSum --- - -test.trimSum <- function() -{ - - ## 'x' must be a vector - for now - checkException(trimSum(matrix(1:10))) - checkException(trimSum(data.frame(1:10))) - checkException(trimSum(list(1:10))) - - ## 'x' must be numeric - checkException(trimSum(letters)) - - ## 'n' must be smaller than the length of x - checkException(trimSum(x=1:10, n=11)) - checkException(trimSum(x=1, n=1)) - - ## Default - x <- trimSum(x=1:10, n=5) - x2 <- c(1:4, 45) - checkEquals(x, x2) - - ## Left - x <- trimSum(x=1:10, n=5, right=FALSE) - x2 <- c(21, 7:10) - checkEquals(x, x2) - - ## NA - x <- trimSum(x=c(1:9, NA), n=5) - x2 <- c(1:4, NA) - checkEquals(x, x2) - - x <- trimSum(x=c(1:9, NA), n=5, na.rm=TRUE) - x2 <- c(1:4, 35) - checkEquals(x, x2) -} - -### }}} -### {{{ Dear Emacs -## Local variables: -## folded-file: t -## End: -### }}} - -###------------------------------------------------------------------------ -### runit.trimSum.R ends here Deleted: trunk/gdata/inst/unitTests/runit.unknown.R =================================================================== --- trunk/gdata/inst/unitTests/runit.unknown.R 2014-04-05 00:14:24 UTC (rev 1781) +++ trunk/gdata/inst/unitTests/runit.unknown.R 2014-04-05 01:08:30 UTC (rev 1782) @@ -1,504 +0,0 @@ -### runit.unknown.R -###------------------------------------------------------------------------ -### What: Tests for Change given unknown value to NA and vice versa methods -### $Id$ -### Time-stamp: <2006-10-30 17:46:21 ggorjan> -###------------------------------------------------------------------------ - -### {{{ --- Test setup --- - -if(FALSE) { - library("RUnit") - library("gdata") -} - -### {{{ --- Vectors --- - -intUnk <- 9999 -xInt <- as.integer(c(NA, 1:2, NA, 5, 6, 7, 8, 9)) -xIntUnk <- as.integer(c(intUnk, 1:2, intUnk, 5, 6, 7, 8, 9)) -xIntUnkTest <- xIntUnk %in% intUnk - -numUnk <- 0 -xNum <- c(9999, NA, 1.5, NA, 5, 6, 7, 8, 9) -xNumUnk <- c(9999, 0, 1.5, 0, 5, 6, 7, 8, 9) -xNumUnkTest <- xNumUnk %in% numUnk - -chaUnk <- "notAvail" -chaUnk1 <- "-" -xCha <- c("A", "B", NA, "C", NA, "-", "7", "8", "9") -xChaUnk <- c("A", "B", chaUnk, "C", chaUnk, "-", "7", "8", "9") -xChaUnk1 <- c("A", "B", chaUnk1, "C", chaUnk1, "-", "7", "8", "9") -xChaUnkTest <- xChaUnk %in% chaUnk -xChaUnk1Test <- xChaUnk %in% chaUnk1 - -facUnk <- "notAvail" -facUnk1 <- "NA" -xFac <- factor(c("A", "0", 0, "NA", "NA", intUnk, numUnk, "-", NA)) -xFacUnk <- factor(c("A", "0", 0, "NA", "NA", intUnk, numUnk, "-", facUnk)) -xFacUnk1 <- factor(c("A", "0", 0, "NA", "NA", intUnk, numUnk, "-", facUnk1)) -xFacUnkTest <- c(0, 0, 0, 0, 0, 0, 0, 0, 1) -xFacUnkTest <- as.logical(xFacUnkTest) -xFacUnk1Test <- c(0, 0, 0, 1, 1, 0, 0, 0, 1) -xFacUnk1Test <- as.logical(xFacUnk1Test) -xFac1 <- factor(c("A", "0", 0, NA, NA, intUnk, numUnk, "-", NA)) - -facLev <- "A" -xFacUnkLev <- factor(c("A", "0", 0, "NA", "NA", intUnk, numUnk, "-", "A")) -xFacUnkLevTest <- c(1, 0, 0, 0, 0, 0, 0, 0, 1) -xFacUnkLevTest <- as.logical(xFacUnkLevTest) - -dateUnk <- as.Date("2006-08-14") -tmp <- as.Date("2006-08-15") -xDate <- c(tmp, NA) -xDateUnk <- c(tmp, dateUnk) -xDateTest <- c(FALSE, TRUE) - -xDate1Unk <- c(tmp, dateUnk, NA) -xDate1Test <- c(FALSE, TRUE, FALSE) - -POSIXltUnk <- strptime("2006-08-14", format="%Y-%m-%d") -tmp <- strptime("2006-08-15", format="%Y-%m-%d") -xPOSIXlt <- c(tmp, NA) -xPOSIXltUnk <- c(tmp, POSIXltUnk) -xPOSIXltTest <- c(FALSE, TRUE) - -xPOSIXlt1Unk <- c(tmp, POSIXltUnk, NA) -xPOSIXlt1Test <- c(FALSE, TRUE, FALSE) - -POSIXctUnk <- as.POSIXct(strptime("2006-08-14 01:01:01", format="%Y-%m-%d %H:%M:%S")) -tmp <- as.POSIXct(strptime("2006-08-15 01:01:01", format="%Y-%m-%d %H:%M:%S")) -xPOSIXct <- c(tmp, NA) -xPOSIXctUnk <- c(tmp, POSIXctUnk) -xPOSIXctTest <- xPOSIXltTest - -xPOSIXct1Unk <- c(tmp, POSIXctUnk, NA) -xPOSIXct1Test <- xPOSIXlt1Test - -### }}} -### {{{ --- Lists and data.frames --- - -xList <- list(xInt, xCha, xNum, xFac) -xListN <- list(int=xInt, cha=xCha, num=xNum, fac=xFac) -xListUnk <- list(xIntUnk, xChaUnk, xNumUnk, xFacUnk) -xListUnkTest <- list(xIntUnkTest, xChaUnkTest, xNumUnkTest, xFacUnkTest) -xListNUnk <- list(int=xIntUnk, cha=xChaUnk, num=xNumUnk, fac=xFacUnk) -xListNUnkTest <- list(int=xIntUnkTest, cha=xChaUnkTest, num=xNumUnkTest, fac=xFacUnkTest) - -xDF <- as.data.frame(xListN) -xDF$cha <- as.character(xDF$cha) -xDFUnk <- as.data.frame(xListNUnk) -xDFUnk$cha <- as.character(xDFUnk$cha) -xDFUnkTest <- as.data.frame(xListNUnkTest) - -unkC <- c(intUnk, chaUnk, numUnk, facUnk) -unkL <- list(intUnk, chaUnk, numUnk, facUnk) -unkLN <- list(num=numUnk, cha=chaUnk, fac=facUnk, int=intUnk) ## mixed as it is named -unkLMN <- list(cha=chaUnk, int=intUnk, num=c(intUnk, numUnk), - fac=c(chaUnk1, facUnk)) - -xListMNUnkF <- list(int=as.integer(c(9999, 1, 2, 9999, 5, 6, 7, 8, 9)), - cha=c("A", "B", "notAvail", "C", "notAvail", "-", "7", "8", "9"), - num=c(9999, 0, 1.5, 0, 5, 6, 7, 8, 9), - fac=factor(c("A", "0", "0", "NA", "NA", 9999, "0", "-", "notAvail"))) -xListMNUnkFTest <- list(int=c(1, 0, 0, 1, 0, 0, 0, 0, 0), - cha=c(0, 0, 1, 0, 1, 0, 0, 0, 0), - num=c(1, 1, 0, 1, 0, 0, 0, 0, 0), - fac=c(0, 0, 0, 0, 0, 0, 0, 1, 1)) -xListMNUnkFTest <- lapply(xListMNUnkFTest, as.logical) -xListMNF <- list(int=as.integer(c(NA, 1, 2, NA, 5, 6, 7, 8, 9)), - cha=c("A", "B", NA, "C", NA, "-", "7", "8", "9"), - num=c(NA, NA, 1.5, NA, 5, 6, 7, 8, 9), - fac=factor(c("A", "0", "0", "NA", "NA", "9999", "0", NA, NA))) - -xDFMUnkF <- as.data.frame(xListMNUnkF) -xDFMUnkF$cha <- as.character(xDFMUnkF$cha) -xDFMUnkFTest <- as.data.frame(xListMNUnkFTest) -xDFMF <- as.data.frame(xListMNF) -xDFMF$cha <- as.character(xDFMF$cha) - -unk1 <- 555555 -xListUnk1 <- list(as.integer(c(unk1, 1, 2, unk1, 5, 6, 7, 8, 9)), - c("A", "B", unk1, "C", unk1, "-", "7", "8", "9"), - c(9999, unk1, 1.5, unk1, 5, 6, 7, 8, 9), - factor(c("A", "0", "0", "NA", "NA", "9999", "0", "-", unk1))) -xListUnk1Test <- lapply(xListUnk1, function(x) x %in% unk1) -xListNUnk1 <- xListUnk1 -names(xListNUnk1) <- c("int", "cha", "num", "fac") -xDFUnk1 <- as.data.frame(xListNUnk1) -xDFUnk1$cha <- as.character(xDFUnk1$cha) -xDFUnk1Test <- as.data.frame(xListUnk1Test) -names(xDFUnk1Test) <- names(xListNUnk1) - -unkC2 <- c(0, "notAvail") -xListUnk2 <- list(as.integer(c(unkC2[1], 1, 2, unkC2[1], 5, 6, 7, 8, 9)), - c("A", "B", unkC2[2], "C", unkC2[2], "-", "7", "8", "9"), - c(9999, as.numeric(unkC2[1]), 1.5, as.numeric(unkC2[1]), 5, 6, 7, 8, 9), - factor(c("A", "0", "0", "NA", "NA", "9999", "0", "-", unkC2[2]))) -xListNUnk2 <- xListUnk2 -names(xListNUnk2) <- c("int", "cha", "num", "fac") -xDFUnk2 <- as.data.frame(xListNUnk2) -xDFUnk2$cha <- as.character(xDFUnk2$cha) - -xListUnk2Test <- xListUnk2 -xListUnk2Test[[1]] <- xListUnk2Test[[1]] %in% unkC2[1] -xListUnk2Test[[2]] <- xListUnk2Test[[2]] %in% unkC2[2] -xListUnk2Test[[3]] <- xListUnk2Test[[3]] %in% unkC2[1] -xListUnk2Test[[4]] <- xListUnk2Test[[4]] %in% unkC2[2] -xListNUnk2Test <- xListUnk2Test -names(xListNUnk2Test) <- names(xListNUnk2) -xDFUnk2Test <- as.data.frame(xListNUnk2Test) - -unkL2 <- as.list(unkC2) -unkLN2 <- unkL2[c(2, 1)] -names(unkLN2) <- c("cha", "int") -xListUnk2a <- list(as.integer(c(NA, 1, 2, NA, 5, 6, 7, 8, 9)), - c("A", "B", unkLN2[[2]], "C", unkLN2[[2]], "-", "7", "8", "9"), - c(9999, NA, 1.5, NA, 5, 6, 7, 8, 9), - factor(c("A", "0", "0", "NA", "NA", "9999", "0", "-", unkLN2[[2]]))) -xListUnk2aTest <- xListUnk2a -xListUnk2aTest[[1]] <- xListUnk2aTest[[1]] %in% unkLN2[1] -xListUnk2aTest[[2]] <- xListUnk2aTest[[2]] %in% unkLN2[2] -xListUnk2aTest[[3]] <- xListUnk2aTest[[3]] %in% unkLN2[1] -xListUnk2aTest[[4]] <- xListUnk2aTest[[4]] %in% unkLN2[2] - -xList2a <- list(xListUnk2a[[1]], - c("A", "B", NA, "C", NA, "-", "7", "8", "9"), - xListUnk2a[[3]], - factor(c("A", NA, NA, "NA", "NA", 9999, NA, "-", NA))) - -### }}} -### {{{ --- Matrix --- - -matUnk <- 9999 -mat <- matrix(1:25, nrow=5, ncol=5) -mat[1, 2] <- NA; mat[1, 4] <- NA; mat[2, 2] <- NA; -mat[3, 2] <- NA; mat[3, 5] <- NA; mat[5, 4] <- NA; -matUnk1 <- mat -matUnk1[1, 2] <- matUnk; matUnk1[1, 4] <- matUnk; matUnk1[2, 2] <- matUnk; -matUnk1[3, 2] <- matUnk; matUnk1[3, 5] <- matUnk; matUnk1[5, 4] <- matUnk; -matUnkTest <- matUnk1Test <- is.na(mat) - -matUnk2Test <- matUnkTest | mat == 1 - -### }}} -### {{{ --- Use of unknown=list(.default=, ...) or similarly named vector --- - -D1 <- "notAvail" -unkLND1 <- list(.default=D1) -xListUnkD1 <- list(as.integer(c(NA, 1:2, NA, 5, 6, 7, 8, 9)), - c("A", "B", D1, "C", D1, "-", "7", "8", "9"), - c(9999, NA, 1.5, NA, 5, 6, 7, 8, 9), - factor(c("A", "0", 0, "NA", "NA", intUnk, numUnk, "-", D1))) -xListUnkD1Test <- lapply(xListUnkD1, function(x) x %in% D1) -xListD1 <- xList - -xListNUnkD1 <- xListUnkD1 -xListNUnkD1Test <- xListUnkD1Test -names(xListNUnkD1) <- names(xListNUnkD1Test) <- names(xListNUnk1) -xListND1 <- xListN - -DSO2 <- c("notAvail", 5678) -unkLNDSO2 <- as.list(DSO2) -names(unkLNDSO2) <- c(".default", "someOther") -xListUnkDSO2 <- list(as.integer(c(NA, 1:2, NA, 5, 6, 7, 8, 9)), - c("A", "B", DSO2[1], "C", DSO2[1], "-", "7", "8", "9"), - c(9999, NA, 1.5, NA, 5, 6, 7, 8, 9), - factor(c("A", "0", 0, "NA", "NA", intUnk, numUnk, "-", DSO2[2]))) -xListUnkDSO2Test <- lapply(xListUnkDSO2, function(x) x %in% DSO2) - -unkLND3 <- list(.default="notAvail", num=0, int=9999) -xListNUnkD3 <- list(int=as.integer(c(unkLND3[[3]], 1:2, unkLND3[[3]], 5, 6, 7, 8, 9)), - cha=c("A", "B", unkLND3[[1]], "C", unkLND3[[1]], "-", "7", "8", "9"), - num=c(9999, unkLND3[[2]], 1.5, unkLND3[[2]], 5, 6, 7, 8, 9), - fac=factor(c("A", "0", 0, "NA", "NA", intUnk, numUnk, "-", unkLND3[[1]]))) -xListNUnkD3Test <- xListNUnkD3 -xListNUnkD3Test$int <- xListNUnkD3Test$int %in% unkLND3[[3]] -xListNUnkD3Test$cha <- xListNUnkD3Test$cha %in% unkLND3[[1]] -xListNUnkD3Test$num <- xListNUnkD3Test$num %in% unkLND3[[2]] -xListNUnkD3Test$fac <- xListNUnkD3Test$fac %in% unkLND3[[1]] - -unkLND2E <- list(.default="notAvail", 9999) - -### }}} - -### }}} -### {{{ --- isUnknown --- - -test.isUnknown <- function() -{ - ## --- base methods for vectors --- - - ## base ... - checkIdentical(isUnknown(xIntUnk, unknown=as.integer(intUnk)), xIntUnkTest) - checkIdentical(isUnknown(xIntUnk, unknown=intUnk), xIntUnkTest) - checkIdentical(isUnknown(xNumUnk, unknown=numUnk), xNumUnkTest) - checkIdentical(isUnknown(xNumUnk, unknown=as.integer(numUnk)), xNumUnkTest) - checkIdentical(isUnknown(xChaUnk, unknown=chaUnk), xChaUnkTest) - checkIdentical(isUnknown(xFacUnk, unknown=facUnk), xFacUnkTest) - - ## multiple values are allowed for vector methods in vector or list form - checkIdentical(isUnknown(xIntUnk, unknown=unkC), xIntUnkTest) - checkIdentical(isUnknown(xIntUnk, unknown=unkL), xIntUnkTest) - - ## NA's in factors - checkIdentical(isUnknown(xFacUnk1, unknown=facUnk1), xFacUnk1Test) - facNA <- factor(c("0", 1, 2, 3, NA, "NA")) - facNATest <- c(FALSE, FALSE, FALSE, FALSE, TRUE, FALSE) - checkIdentical(isUnknown(facNA), facNATest) - - ## Date-time classes - checkIdentical(isUnknown(xDateUnk, unknown=dateUnk), xDateTest) - checkIdentical(isUnknown(xDate1Unk, unknown=dateUnk), xDate1Test) - checkIdentical(isUnknown(xPOSIXltUnk, unknown=POSIXltUnk), xPOSIXltTest) - checkIdentical(isUnknown(xPOSIXlt1Unk, unknown=POSIXltUnk), xPOSIXlt1Test) - checkIdentical(isUnknown(xPOSIXctUnk, unknown=POSIXctUnk), xPOSIXctTest) - checkIdentical(isUnknown(xPOSIXct1Unk, unknown=POSIXctUnk), xPOSIXct1Test) - - ## --- lists and data.frames --- - - ## with vector of single unknown values - checkIdentical(isUnknown(xListUnk, unknown=unkC), xListUnkTest) - checkIdentical(isUnknown(xDFUnk, unknown=unkC), xDFUnkTest) - - ## with list of single unknown values - checkIdentical(isUnknown(xListUnk, unknown=unkL), xListUnkTest) - checkIdentical(isUnknown(xDFUnk, unknown=unkL), xDFUnkTest) - - ## with named list of single unknown values - checkIdentical(isUnknown(xListNUnk, unknown=unkLN), xListNUnkTest) - checkIdentical(isUnknown(xDFUnk, unknown=unkLN), xDFUnkTest) - - ## with named list of multiple unknown values - valid here - checkIdentical(isUnknown(xListMNUnkF, unknown=unkLMN), xListMNUnkFTest) - checkIdentical(isUnknown(xDFMUnkF, unknown=unkLMN), xDFMUnkFTest) - - ## with single unknown value - recycling - checkIdentical(isUnknown(xListUnk1, unknown=unk1), xListUnk1Test) - checkIdentical(isUnknown(xDFUnk1, unknown=unk1), xDFUnk1Test) - - ## with vector of two unknown values - recycling - checkIdentical(isUnknown(xListUnk2, unknown=unkC2), xListUnk2Test) - checkIdentical(isUnknown(xDFUnk2, unknown=unkC2), xDFUnk2Test) - - ## with list of two unknown values - recycling - checkIdentical(isUnknown(xListUnk2, unknown=unkL2), xListUnk2Test) - checkIdentical(isUnknown(xDFUnk2, unknown=unkL2), xDFUnk2Test) - - ## list(.default=) - checkIdentical(isUnknown(x=xListUnkD1, unknown=unkLND1), xListUnkD1Test) - ## list(.default=, someOther=) we do not know someOther, but should work - ## as x is not named - checkIdentical(isUnknown(x=xListUnkDSO2, unknown=unkLNDSO2), xListUnkDSO2Test) - ## list(.default=) in named list - checkIdentical(isUnknown(x=xListNUnkD1, unknown=unkLND1), xListNUnkD1Test) - ## list(.default=, someOther=) OK if someOther is in the named list - checkIdentical(isUnknown(x=xListNUnkD3, unknown=unkLND3), xListNUnkD3Test) - ## list(.default=, 99) ERROR as we do not know where to apply 99 - checkException(isUnknown(x=xListNUnk, unknown=unkLND2E)) - - ## --- matrix --- - - checkIdentical(isUnknown(x=mat, unknown=NA), matUnkTest) - checkIdentical(isUnknown(x=matUnk1, unknown=matUnk), matUnkTest) - checkIdentical(isUnknown(x=matUnk1, unknown=c(1, matUnk)), matUnk2Test) -} - -### }}} -### {{{ --- unknownToNA --- - -test.unknownToNA <- function() -{ - ## --- base methods for vectors --- - - ## base ... - checkIdentical(unknownToNA(xIntUnk, as.integer(intUnk)), xInt) - checkIdentical(unknownToNA(xIntUnk, intUnk), xInt) ## with numeric - checkIdentical(unknownToNA(xNumUnk, numUnk), xNum) - checkIdentical(unknownToNA(xNumUnk, as.integer(numUnk)), xNum) - checkIdentical(unknownToNA(xChaUnk, chaUnk), xCha) - checkIdentical(unknownToNA(xChaUnk, chaUnk), xCha) - checkIdentical(unknownToNA(xFacUnk, facUnk), xFac) - - ## multiple values are allowed for vector methods in vector or list form - checkIdentical(unknownToNA(xIntUnk, unknown=unkC), xInt) - checkIdentical(unknownToNA(xIntUnk, unknown=unkL), xInt) - - ## NA's in factors - checkIdentical(unknownToNA(xFacUnk1, unknown=facUnk1), xFac1) - facNA <- factor(c("0", 1, 2, 3, NA, "NA")) - facNATest <- factor(c("0", 1, 2, 3, NA, NA)) - checkIdentical(unknownToNA(x=facNA, unknown="NA"), facNATest) - - ## Date-time classes - checkIdentical(unknownToNA(xDateUnk, unknown=dateUnk), xDate) - checkIdentical(unknownToNA(xPOSIXltUnk, unknown=POSIXltUnk), xPOSIXlt) - checkIdentical(unknownToNA(xPOSIXctUnk, unknown=POSIXctUnk), xPOSIXct) - - ## --- lists and data.frames --- - - ## with vector of single unknown values - checkIdentical(unknownToNA(xListUnk, unknown=unkC), xList) - checkIdentical(unknownToNA(xDFUnk, unknown=unkC), xDF) - - ## with list of single unknown values - checkIdentical(unknownToNA(xListUnk, unknown=unkL), xList) - checkIdentical(unknownToNA(xDFUnk, unknown=unkL), xDF) - - ## with named list of single unknown values - checkIdentical(unknownToNA(xListNUnk, unknown=unkLN), xListN) - checkIdentical(unknownToNA(xDFUnk, unknown=unkLN), xDF) - - ## with names list of multiple unknown values - must be an error - checkIdentical(unknownToNA(xListMNUnkF, unknown=unkLMN), xListMNF) - checkIdentical(unknownToNA(xDFMUnkF, unknown=unkLMN), xDFMF) - - ## with single unknown value - recycling - checkIdentical(unknownToNA(xListUnk1, unknown=unk1), xList) - checkIdentical(unknownToNA(xDFUnk1, unknown=unk1), xDF) - - ## with vector of two unknown values - recycling - checkIdentical(unknownToNA(xListUnk2, unknown=unkC2), xList) - checkIdentical(unknownToNA(xDFUnk2, unknown=unkC2), xDF) - - ## with list of two unknown values - recycling - checkIdentical(unknownToNA(xListUnk2, unknown=unkL2), xList) - checkIdentical(unknownToNA(xDFUnk2, unknown=unkL2), xDF) - - ## with named list of two unknown values but x is not named so named list - ## does not have any effect --> error as we do not know how to recycle - checkException(unknownToNA(xListUnk2a, unknown=unkLN2)) - - ## but we should get some results with named x - checkIdentical(unknownToNA(xListNUnk2, unknown=unkL2), xListN) - ## not also necesarilly with recycling of names lists, as it is - ## not clear how to properly recycle named lists (only names that match - ## can be really properly recycled) - checkException(unknownToNA(xListNUnk2, unknown=unkLN2)) - checkIdentical(unknownToNA(xDFUnk2, unknown=unkL2), xDF) - checkException(unknownToNA(xDFUnk2, unknown=unkLN2)) - - ## list(.default=) - checkIdentical(unknownToNA(x=xListUnkD1, unknown=unkLND1), xListD1) - ## list(.default=, someOther=) we do not know someOther, but should work - ## as x is not named - checkIdentical(unknownToNA(x=xListUnkDSO2, unknown=unkLNDSO2), xList) - ## list(.default=) in named list - checkIdentical(unknownToNA(x=xListNUnkD1, unknown=unkLND1), xListND1) - ## list(.default=, someOther=) OK if someOther is in the named list - checkIdentical(unknownToNA(x=xListNUnkD3, unknown=unkLND3), xListN) - ## list(.default=, 99) ERROR as we do not know where to apply 99 - checkException(unknownToNA(x=xListNUnk, unknown=unkLND2E)) - - ## --- matrix --- - - checkEquals(unknownToNA(x=matUnk1, unknown=matUnk), mat) -} - -### }}} -### {{{ --- NAToUnknown --- - -test.NAToUnknown <- function() -{ - ## --- base methods for vectors --- - - ## base ... - checkIdentical(NAToUnknown(xInt, as.integer(intUnk)), xIntUnk) - checkIdentical(NAToUnknown(xInt, intUnk), xIntUnk) ## with numeric - checkIdentical(NAToUnknown(xNum, numUnk), xNumUnk) - checkIdentical(NAToUnknown(xNum, as.integer(numUnk)), xNumUnk) - checkIdentical(NAToUnknown(xCha, chaUnk), xChaUnk) - checkIdentical(NAToUnknown(xCha, chaUnk), xChaUnk) - checkIdentical(NAToUnknown(xFac, facUnk), xFacUnk) - - ## only single values are allowed for vector methods - checkException(NAToUnknown(xInt, unknown=unkC)) - checkException(NAToUnknown(xInt, unknown=unkL)) - - ## and they should not already be in x unless force=TRUE - checkException(NAToUnknown(xCha, unknown=chaUnk1)) - checkIdentical(NAToUnknown(xCha, unknown=chaUnk1, force=TRUE), xChaUnk1) - - checkException(NAToUnknown(xFac, unknown=facLev)) - checkIdentical(NAToUnknown(xFac, unknown=facLev, force=TRUE), xFacUnkLev) - - ## NA's in factors - checkIdentical(NAToUnknown(xFac, unknown=facUnk1, force=TRUE), xFacUnk1) - facNA <- factor(c("0", 1, 2, 3, NA, NA)) - facNATest <- factor(c("0", 1, 2, 3, "NA", "NA")) - checkIdentical(NAToUnknown(x=facNA, unknown="NA"), facNATest) - - ## Date-time classes - checkIdentical(NAToUnknown(xDate, unknown=dateUnk), xDateUnk) - checkIdentical(NAToUnknown(xPOSIXlt, unknown=POSIXltUnk), xPOSIXltUnk) - checkIdentical(NAToUnknown(xPOSIXct, unknown=POSIXctUnk), xPOSIXctUnk) - - ## --- lists and data.frames --- - - ## with vector of single unknown values - checkIdentical(NAToUnknown(xList, unknown=unkC), xListUnk) - checkIdentical(NAToUnknown(xDF, unknown=unkC), xDFUnk) - - ## with list of single unknown values - checkIdentical(NAToUnknown(xList, unknown=unkL), xListUnk) - checkIdentical(NAToUnknown(xDF, unknown=unkL), xDFUnk) - - ## with named list of single unknown values - checkIdentical(NAToUnknown(xListN, unknown=unkLN), xListNUnk) - checkIdentical(NAToUnknown(xDF, unknown=unkLN), xDFUnk) - - ## with names list of multiple unknown values - must be an error - checkException(NAToUnknown(xListN, unknown=unkLMN)) - checkException(NAToUnknown(xDF, unknown=unkLMN)) - - ## with single unknown value - recycling - checkIdentical(NAToUnknown(xList, unknown=unk1), xListUnk1) - checkIdentical(NAToUnknown(xDF, unknown=unk1), xDFUnk1) - - ## with vector of two unknown values - recycling - checkIdentical(NAToUnknown(xList, unknown=unkC2), xListUnk2) - checkIdentical(NAToUnknown(xDF, unknown=unkC2), xDFUnk2) - - ## with list of two unknown values - recycling - checkIdentical(NAToUnknown(xList, unknown=unkL2), xListUnk2) - checkIdentical(NAToUnknown(xDF, unknown=unkL2), xDFUnk2) - - ## with named list of two unknown values but x is not named so named list - ## does not have any effect --> error as we do not know how to recycle - checkException(NAToUnknown(xList, unknown=unkLN2)) - - ## but we should get some results with named x - checkIdentical(NAToUnknown(xListN, unknown=unkL2), xListNUnk2) - ## not also necesarilly with recycling of names lists, as it is - ## not clear how to properly recycle named lists (only names that match - ## can be really properly recycled) - checkException(NAToUnknown(xListN, unknown=unkLN2)) - checkIdentical(NAToUnknown(xDF, unknown=unkL2), xDFUnk2) - checkException(NAToUnknown(xDF, unknown=unkLN2)) - - ## list(.default=) - checkIdentical(NAToUnknown(x=xList, unknown=unkLND1), xListUnkD1) - ## list(.default=, someOther=) we do not know someOther, but should work - ## as x is not named - checkIdentical(NAToUnknown(x=xList, unknown=unkLNDSO2), xListUnkDSO2) - ## list(.default=) in named list - checkIdentical(NAToUnknown(x=xListN, unknown=unkLND1), xListNUnkD1) - ## list(.default=, someOther=) OK if someOther is in the named list - checkIdentical(NAToUnknown(x=xListN, unknown=unkLND3), xListNUnkD3) - ## list(.default=, 99) ERROR as we do not know where to apply 99 - checkException(NAToUnknown(x=xListN, unknown=unkLND2E)) - - ## --- matrix --- - - checkEquals(NAToUnknown(x=mat, unknown=matUnk), matUnk1) -} - -### }}} -### {{{ Dear Emacs -### Local variables: -### folded-file: t -### End: -### }}} - -###------------------------------------------------------------------------ -### runit.unknown.R ends here Deleted: trunk/gdata/inst/unitTests/runit.wideByFactor.R =================================================================== --- trunk/gdata/inst/unitTests/runit.wideByFactor.R 2014-04-05 00:14:24 UTC (rev 1781) +++ trunk/gdata/inst/unitTests/runit.wideByFactor.R 2014-04-05 01:08:30 UTC (rev 1782) @@ -1,55 +0,0 @@ -### runit.wideByFactor.R -###------------------------------------------------------------------------ -### What: Reshape by factor levels - unit tests -### $Id$ -### Time-stamp: <2008-12-30 11:58:50 ggorjan> -###------------------------------------------------------------------------ - -### {{{ --- Test setup --- - -if(FALSE) { - library("RUnit") - library("gdata") -} - -### }}} -### {{{ --- wideByFactor --- - -test.wideByFactor <- function() -{ - n <- 10 - f <- 2 - tmp <- data.frame(y1=(1:n)/2, - y2=(n:1)*2, - f1=factor(rep(letters[1:f], n/2)), - f2=factor(c(rep(c("M"), n/2), rep(c("F"), n/2))), - c1=1:n, - c2=2*(1:n)) - - ## 'x' must be a data.frame - checkException(wideByFactor(x=1:10)) - checkException(wideByFactor(x=matrix(1:10))) - ## 'factor' can be only of length one - checkException(wideByFactor(x=tmp, factor=c("f1", "f2"))) - ## column defined in 'factor' must be a factor - checkException(wideByFactor(x=tmp, factor="c1")) - - tmp2 <- wideByFactor(x=tmp, factor="f1", common=c("c1", "c2"), sort=FALSE) - checkEquals(tmp2[c("c1", "c2")], tmp[c("c1", "c2")]) - checkEquals(names(tmp2), c("c1", "c2", "f1", "y1.a", "y2.a", "f2.a", "y1.b", "y2.b", "f2.b")) - checkEquals(tmp2$y1.a, c(0.5, NA, 1.5, NA, 2.5, NA, 3.5, NA, 4.5, NA)) - checkEquals(tmp2$f2.a, factor(c("M", NA, "M", NA, "M", NA, "F", NA, "F", NA))) - tmp2 <- wideByFactor(x=tmp, factor="f1", common=c("c1", "c2... [truncated message content] |
From: <wa...@us...> - 2014-04-05 00:14:28
|
Revision: 1781 http://sourceforge.net/p/r-gregmisc/code/1781 Author: warnes Date: 2014-04-05 00:14:24 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Update NEWS Modified Paths: -------------- trunk/gplots/inst/NEWS Modified: trunk/gplots/inst/NEWS =================================================================== --- trunk/gplots/inst/NEWS 2014-04-05 00:10:13 UTC (rev 1780) +++ trunk/gplots/inst/NEWS 2014-04-05 00:14:24 UTC (rev 1781) @@ -8,9 +8,12 @@ Enhancements: -- When the row or column trace is enabled, show the corresponding - reference line in the color key. +- In heatmap.2, when the row or column trace is enabled, show the + corresponding reference line in the color key. +- In heatmap.2, a new 'extrafun' argument is provided that allows the + user to specify a function to be called before the function returns. + This allows the user to add additional plots to the page. Release 2.12.1 - 2013-10-14 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-05 00:10:18
|
Revision: 1780 http://sourceforge.net/p/r-gregmisc/code/1780 Author: warnes Date: 2014-04-05 00:10:13 +0000 (Sat, 05 Apr 2014) Log Message: ----------- Add 'extrafun' argument to heatmap.2 to allow the user to perform additional customization by providing a function to be called before heatmap.2 exits. Modified Paths: -------------- trunk/gplots/R/heatmap.2.R trunk/gplots/man/heatmap.2.Rd Modified: trunk/gplots/R/heatmap.2.R =================================================================== --- trunk/gplots/R/heatmap.2.R 2014-04-04 22:37:12 UTC (rev 1779) +++ trunk/gplots/R/heatmap.2.R 2014-04-05 00:10:13 UTC (rev 1780) @@ -78,6 +78,7 @@ lwid = NULL, ## extras + extrafun=NULL, ... ) { @@ -641,9 +642,6 @@ } } - - - } else plot.new() @@ -655,6 +653,9 @@ color=retval$col ) + ## If user has provided an extra function, call it. + if(!is.null(extrafun)) + extrafun() invisible( retval ) } Modified: trunk/gplots/man/heatmap.2.Rd =================================================================== --- trunk/gplots/man/heatmap.2.Rd 2014-04-04 22:37:12 UTC (rev 1779) +++ trunk/gplots/man/heatmap.2.Rd 2014-04-05 00:10:13 UTC (rev 1780) @@ -3,7 +3,7 @@ \title{ Enhanced Heat Map } \description{ A heat map is a false color image (basically - \code{\link{image}(t(x))}) with a dendrogram added to the left side + \code{\link{image}(t(x))}) with a dendrogram added to the left side and/or to the top. Typically, reordering of the rows and columns according to some set of values (row or column means) within the restrictions imposed by the dendrogram is carried out. @@ -90,6 +90,7 @@ lwid = NULL, # extras + extrafun=NULL, ... ) } @@ -112,7 +113,7 @@ \item{hclustfun}{function used to compute the hierarchical clustering when \code{Rowv} or \code{Colv} are not dendrograms. Defaults to \code{\link{hclust}}.} - \item{dendrogram}{character string indicating whether to draw 'none', + \item{dendrogram}{character string indicating whether to draw 'none', 'row', 'column' or 'both' dendrograms. Defaults to 'both'. However, if Rowv (or Colv) is FALSE or NULL and dendrogram is 'both', then a warning is issued and Rowv (or Colv) arguments are honoured.} @@ -182,12 +183,12 @@ for the row or column axis labeling. The defaults currently only use number of rows or columns, respectively.} \item{labRow, labCol}{character vectors with row and column labels to - use; these default to \code{rownames(x)} or \code{colnames(x)}, + use; these default to \code{rownames(x)} or \code{colnames(x)}, respectively.} \item{srtRow, srtCol}{angle of row/column labels, in degrees from horizontal} \item{adjRow, adjCol}{2-element vector giving the (left-right, top-bottom) justification of row/column labels (relative to the text - orientation).} + orientation).} \item{offsetRow, offsetCol}{Number of character-width spaces to place between row/column labels and the edge of the plotting region.} % Color key and density info @@ -211,7 +212,9 @@ % figure layout \item{lmat, lhei, lwid}{visual layout: position matrix, column height, column width. See below for details} - \item{...}{additional arguments passed on to \code{\link{image}} } % + \item{extrafun}{A function to be called after all other work. See + examples.} + \item{...}{additional arguments passed on to \code{\link{image}} } } \details{ If either \code{Rowv} or \code{Colv} are dendrograms they are honored @@ -221,11 +224,11 @@ If either is a vector (of \dQuote{weights}) then the appropriate dendrogram is reordered according to the supplied values subject to - the constraints imposed by the dendrogram, by \code{\link{reorder}(dd, + the constraints imposed by the dendrogram, by \code{\link{reorder}(dd, Rowv)}, in the row case. %% If either is missing, as by default, then the ordering of the - corresponding dendrogram is by the mean value of the rows/columns, + corresponding dendrogram is by the mean value of the rows/columns, i.e., in the case of rows, \code{Rowv <- rowMeans(x, na.rm=na.rm)}. %% If either is \code{\link{NULL}}, \emph{no reordering} will be done for @@ -237,7 +240,7 @@ The default colors range from red to white (\code{heat.colors}) and are not pretty. Consider using enhancements such - as the \pkg{RColorBrewer} package, + as the \pkg{RColorBrewer} package, \url{http://cran.r-project.org/src/contrib/PACKAGES.html#RColorBrewer} to select better colors. @@ -286,9 +289,9 @@ \item{hline}{center-line value used for row trace, present only if \code{trace="both"} or \code{trace="row"} } \item{colorTable}{A three-column data frame providing the lower and upper - bound and color for each bin} + bound and color for each bin} } -\author{Andy Liaw, original; R. Gentleman, M. Maechler, W. Huber, +\author{Andy Liaw, original; R. Gentleman, M. Maechler, W. Huber, G. Warnes, revisions.} \seealso{\code{\link{image}}, \code{\link{hclust}}} @@ -303,7 +306,7 @@ ## ## demonstrate the effect of row and column dendogram options ## - heatmap.2(x) ## default - dendrogram plotted and reordering done. + heatmap.2(x) ## default - dendrogram plotted and reordering done. heatmap.2(x, dendrogram="none") ## no dendrogram plotted, but reordering done. heatmap.2(x, dendrogram="row") ## row dendrogram plotted and row reordering done. heatmap.2(x, dendrogram="col") ## col dendrogram plotted and col reordering done. @@ -341,7 +344,21 @@ heatmap.2(x, srtRow=0, srtCol=90, offsetRow=2, offsetCol=2) heatmap.2(x, srtRow=0, srtCol=90, offsetRow=-1, offsetCol=-1) - ## + ## Show how to use 'extrafun' to replace the 'key' with a scatterplot + lmat <- rbind( c(5,3,4), c(2,1,4) ) + lhei <- c(1.5, 4) + lwid <- c(1.5, 4, 0.75) + + myplot <- function() { + oldpar <- par("mar") + par(mar=c(5.1, 4.1, 0.5, 0.5)) + plot(mpg ~ hp, data=x) + } + + heatmap.2(x, lmat=lmat, lhei=lhei, lwid=lwid, key=FALSE, extrafun=myplot) + + + ## ## Show effect of z-score scaling within columns, blue-red color scale ## hv <- heatmap.2(x, col=bluered, scale="column", tracecol="#303030") @@ -364,18 +381,18 @@ ## ## A more decorative heatmap, with z-score scaling along columns ## - hv <- heatmap.2(x, col=cm.colors(255), scale="column", - RowSideColors=rc, ColSideColors=cc, margin=c(5, 10), - xlab="specification variables", ylab= "Car Models", - main="heatmap(<Mtcars data>, ..., scale=\"column\")", + hv <- heatmap.2(x, col=cm.colors(255), scale="column", + RowSideColors=rc, ColSideColors=cc, margin=c(5, 10), + xlab="specification variables", ylab= "Car Models", + main="heatmap(<Mtcars data>, ..., scale=\"column\")", tracecol="green", density="density") ## Note that the breakpoints are now symmetric about 0 - + %% want example using the `add.exp' argument! data(attitude) @@ -398,7 +415,7 @@ data(USJudgeRatings) symnum( cU <- cor(USJudgeRatings) ) - hU <- heatmap.2(cU, Rowv=FALSE, symm=TRUE, col=topo.colors(16), + hU <- heatmap.2(cU, Rowv=FALSE, symm=TRUE, col=topo.colors(16), distfun=function(c) as.dist(1 - c), trace="none") ## The Correlation matrix with same reordering: @@ -407,8 +424,8 @@ # now with the correlation matrix on the plot itself - heatmap.2(cU, Rowv=FALSE, symm=TRUE, col=rev(heat.colors(16)), - distfun=function(c) as.dist(1 - c), trace="none", + heatmap.2(cU, Rowv=FALSE, symm=TRUE, col=rev(heat.colors(16)), + distfun=function(c) as.dist(1 - c), trace="none", cellnote=hM) ## genechip data examples @@ -418,15 +435,15 @@ pms <- SpikeIn@pm # just the data, scaled across rows - heatmap.2(pms, col=rev(heat.colors(16)), main="SpikeIn@pm", - xlab="Relative Concentration", ylab="Probeset", + heatmap.2(pms, col=rev(heat.colors(16)), main="SpikeIn@pm", + xlab="Relative Concentration", ylab="Probeset", scale="row") # fold change vs "12.50" sample data <- pms / pms[, "12.50"] data <- ifelse(data>1, data, -1/data) - heatmap.2(data, breaks=16, col=redgreen, tracecol="blue", - main="SpikeIn@pm Fold Changes\nrelative to 12.50 sample", + heatmap.2(data, breaks=16, col=redgreen, tracecol="blue", + main="SpikeIn@pm Fold Changes\nrelative to 12.50 sample", xlab="Relative Concentration", ylab="Probeset") } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-04 22:37:16
|
Revision: 1779 http://sourceforge.net/p/r-gregmisc/code/1779 Author: warnes Date: 2014-04-04 22:37:12 +0000 (Fri, 04 Apr 2014) Log Message: ----------- Update for gplots 2.13.0 Modified Paths: -------------- trunk/gplots/DESCRIPTION trunk/gplots/inst/NEWS Modified: trunk/gplots/DESCRIPTION =================================================================== --- trunk/gplots/DESCRIPTION 2014-04-04 21:32:51 UTC (rev 1778) +++ trunk/gplots/DESCRIPTION 2014-04-04 22:37:12 UTC (rev 1779) @@ -4,12 +4,12 @@ Depends: R (>= 3.0) Imports: gtools, gdata, stats, caTools, KernSmooth Suggests: grid, MASS -Version: 2.12.1 -Date: 2013-10-14 +Version: 2.13.0 +Date: 2014-04-04 Author: Gregory R. Warnes, Ben Bolker, Lodewijk Bonebakker, Robert Gentleman, Wolfgang Huber Andy Liaw, Thomas Lumley, Martin Maechler, Arni Magnusson, Steffen Moeller, Marc Schwartz, Bill - Venables + Venables Maintainer: Gregory R. Warnes <gr...@wa...> License: GPL-2 NeedsCompilation: No Modified: trunk/gplots/inst/NEWS =================================================================== --- trunk/gplots/inst/NEWS 2014-04-04 21:32:51 UTC (rev 1778) +++ trunk/gplots/inst/NEWS 2014-04-04 22:37:12 UTC (rev 1779) @@ -1,3 +1,18 @@ +Release 2.13.0 - 2014-04-04 +--------------------------- + +Bug Fixes: + +- heatmap.2 was not properly handling row trace reference line ('hline'). + Patch submitted by Ilia Kats. + +Enhancements: + +- When the row or column trace is enabled, show the corresponding + reference line in the color key. + + + Release 2.12.1 - 2013-10-14 --------------------------- @@ -23,7 +38,7 @@ finite values. Other Changes: - + - Changes to overplot() to avoid warnings from upcoming enhancements to R CMD check. - Move several packages from Depends to Imports or Suggests. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <wa...@us...> - 2014-04-04 21:32:57
|
Revision: 1778 http://sourceforge.net/p/r-gregmisc/code/1778 Author: warnes Date: 2014-04-04 21:32:51 +0000 (Fri, 04 Apr 2014) Log Message: ----------- Fix handling of row trace (hline). Bug report and patch provided by Ilia Kats. Modified Paths: -------------- trunk/gplots/R/heatmap.2.R Modified: trunk/gplots/R/heatmap.2.R =================================================================== --- trunk/gplots/R/heatmap.2.R 2014-03-19 10:04:49 UTC (rev 1777) +++ trunk/gplots/R/heatmap.2.R 2014-04-04 21:32:51 UTC (rev 1778) @@ -86,9 +86,9 @@ x <- (x-low)/(high - low) x } - + retval <- list() - + scale <- if(symm && missing(scale)) "none" else match.arg(scale) dendrogram <- match.arg(dendrogram) trace <- match.arg(trace) @@ -115,8 +115,8 @@ Colv <- FALSE else if( Colv=="Rowv" && !isTRUE(Rowv) ) Colv <- FALSE - - + + if(length(di <- dim(x)) != 2 || !is.numeric(x)) stop("`x' must be a numeric matrix") @@ -141,10 +141,10 @@ dendrogram <- "column" else dedrogram <- "none" - + warning("Discrepancy: Rowv is FALSE, while dendrogram is `", dendrogram, "'. Omitting row dendogram.") - + } } @@ -157,13 +157,13 @@ dendrogram <- "row" else dendrogram <- "none" - + warning("Discrepancy: Colv is FALSE, while dendrogram is `", dendrogram, "'. Omitting column dendogram.") } } - - + + ## by default order by row/col mean ## if(is.null(Rowv)) Rowv <- rowMeans(x, na.rm = na.rm) ## if(is.null(Colv)) Colv <- colMeans(x, na.rm = na.rm) @@ -175,32 +175,32 @@ if(inherits(Rowv, "dendrogram")) { ddr <- Rowv ## use Rowv 'as-is', when it is dendrogram - rowInd <- order.dendrogram(ddr) + rowInd <- order.dendrogram(ddr) } else if (is.integer(Rowv)) { ## Compute dendrogram and do reordering based on given vector hcr <- hclustfun(distfun(x)) ddr <- as.dendrogram(hcr) ddr <- reorder(ddr, Rowv) - + rowInd <- order.dendrogram(ddr) if(nr != length(rowInd)) stop("row dendrogram ordering gave index of wrong length") } - else if (isTRUE(Rowv)) + else if (isTRUE(Rowv)) { ## If TRUE, compute dendrogram and do reordering based on rowMeans Rowv <- rowMeans(x, na.rm = na.rm) hcr <- hclustfun(distfun(x)) ddr <- as.dendrogram(hcr) ddr <- reorder(ddr, Rowv) - + rowInd <- order.dendrogram(ddr) if(nr != length(rowInd)) stop("row dendrogram ordering gave index of wrong length") } else { rowInd <- nr:1 } - + ## if( dendrogram %in% c("both","column") ) ## { if(inherits(Colv, "dendrogram")) @@ -247,7 +247,7 @@ retval$colInd <- colInd retval$call <- match.call() - + ## reorder x & cellnote x <- x[rowInd, colInd] x.unscaled <- x @@ -281,10 +281,10 @@ { if( missing(col) || is.function(col) ) breaks <- 16 - else + else breaks <- length(col)+1 } - + if(length(breaks)==1) { if(!symbreaks) @@ -308,7 +308,7 @@ x[x<min.breaks] <- min.breaks x[x>max.breaks] <- max.breaks - + ## Calculate the plot layout if( missing(lhei) || is.null(lhei) ) lhei <- c(keysize, 4) @@ -319,7 +319,7 @@ if( missing(lmat) || is.null(lmat) ) { lmat <- rbind(4:3, 2:1) - + if(!missing(ColSideColors)) { ## add middle row to layout if(!is.character(ColSideColors) || length(ColSideColors) != nc) stop("'ColSideColors' must be a character vector of length ncol(x)") @@ -336,7 +336,7 @@ lmat[is.na(lmat)] <- 0 } - + if(length(lhei) != nrow(lmat)) stop("lhei must have length = nrow(lmat) = ", nrow(lmat)) @@ -386,7 +386,7 @@ retval$colDendrogram <- ddc retval$breaks <- breaks retval$col <- col - + ## fill 'na' positions with na.color if(!invalid(na.color) & any(is.na(x))) { @@ -421,7 +421,7 @@ y=par("usr")[3] - (1.0 + offsetCol) * strheight("M"), labels=labCol, ##pos=1, - adj=adjCol, + adj=adjCol, cex=cexCol, srt=srtCol) par(xpd=xpd.orig) @@ -487,7 +487,7 @@ xright=nrow(x)+1, ytop = (ncol(x)+1-rsep)-0.5 - sepwidth[2], lty=1, lwd=1, col=sepcolor, border=sepcolor) - + ## show traces min.scale <- min(breaks) max.scale <- max(breaks) @@ -510,7 +510,7 @@ } } - + if(trace %in% c("both","row") ) { retval$hline <- hline @@ -519,7 +519,7 @@ { if(!is.null(hline)) { - abline(h=i + hline, col=linecol, lty=2) + abline(h=i - 0.5 + hline.vals, col=linecol, lty=2) } yv <- rep(i, ncol(x.scaled)) + x.scaled[i,] - 0.5 yv <- rev(c(yv[1], yv)) @@ -573,7 +573,7 @@ } else { - min.raw <- min(x, na.rm=TRUE) ## Again, modified to use scaled + min.raw <- min(x, na.rm=TRUE) ## Again, modified to use scaled max.raw <- max(x, na.rm=TRUE) ## or unscaled (SD 12/2/03) } @@ -595,12 +595,11 @@ if(density.info=="density") { - ## Experimental : also plot density of data dens <- density(x, adjust=densadj, na.rm=TRUE) omit <- dens$x < min(breaks) | dens$x > max(breaks) dens$x <- dens$x[-omit] dens$y <- dens$y[-omit] - dens$x <- scale01(dens$x,min.raw,max.raw) + dens$x <- scale01(dens$x, min.raw, max.raw) lines(dens$x, dens$y / max(dens$y) * 0.95, col=denscol, lwd=1) axis(2, at=pretty(dens$y)/max(dens$y) * 0.95, pretty(dens$y) ) title("Color Key\nand Density Plot") @@ -610,7 +609,7 @@ else if(density.info=="histogram") { h <- hist(x, plot=FALSE, breaks=breaks) - hx <- scale01(breaks,min.raw,max.raw) + hx <- scale01(breaks, min.raw, max.raw) hy <- c(h$counts, h$counts[length(h$counts)]) lines(hx, hy/max(hy)*0.95, lwd=1, type="s", col=denscol) axis(2, at=pretty(hy)/max(hy) * 0.95, pretty(hy) ) @@ -621,6 +620,30 @@ else title("Color Key") + + if(trace %in% c("both","column") ) + { + vline.vals <- scale01(vline, min.raw, max.raw) + if(!is.null(vline)) + { + abline(v=vline.vals, col=linecol, lty=2) + } + } + + + if(trace %in% c("both","row") ) + { + hline.vals <- scale01(hline, min.raw, max.raw) + if(!is.null(hline)) + { + abline(v=hline.vals, col=linecol, lty=2) + + } + } + + + + } else plot.new() @@ -630,8 +653,8 @@ low=retval$breaks[-length(retval$breaks)], high=retval$breaks[-1], color=retval$col - ) + ) - + invisible( retval ) } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ar...@us...> - 2014-03-19 10:04:52
|
Revision: 1777 http://sourceforge.net/p/r-gregmisc/code/1777 Author: arnima Date: 2014-03-19 10:04:49 +0000 (Wed, 19 Mar 2014) Log Message: ----------- change warning message to R standards Modified Paths: -------------- trunk/gdata/R/keep.R Modified: trunk/gdata/R/keep.R =================================================================== --- trunk/gdata/R/keep.R 2014-03-01 20:15:05 UTC (rev 1776) +++ trunk/gdata/R/keep.R 2014-03-19 10:04:49 UTC (rev 1777) @@ -2,8 +2,8 @@ { if(missing(...) && missing(list)) { - warning("Keep something, or use rm(list=ls()) to clear workspace. ", - "Nothing was removed.") + warning("keep something, or use rm(list=ls()) to clear workspace - ", + "nothing was removed") return(invisible(NULL)) } names <- as.character(substitute(list(...)))[-1] @@ -11,8 +11,8 @@ keep.elements <- match(list, ls(1,all.names=all)) if(any(is.na(keep.elements))) { - warning("You tried to keep \"", list[which(is.na(keep.elements))[1]], - "\" which doesn't exist in workspace. Nothing was removed.", sep="") + warning("you tried to keep \"", list[which(is.na(keep.elements))[1]], + "\" which doesn't exist in workspace - nothing was removed", sep="") return(invisible(NULL)) } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |