[Analogue-commits] r268 - in pkg: . R inst man tests/Examples
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun May 6 22:30:49 CEST 2012
Author: gsimpson
Date: 2012-05-06 22:30:48 +0200 (Sun, 06 May 2012)
New Revision: 268
Modified:
pkg/DESCRIPTION
pkg/R/Stratiplot.R
pkg/R/Stratiplot.formula.R
pkg/inst/ChangeLog
pkg/man/Stratiplot.Rd
pkg/tests/Examples/analogue-Ex.Rout.save
Log:
fix Stratiplot.formula to pass 'NA's through to lattice; bump to 0.9-5
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2012-05-04 13:10:44 UTC (rev 267)
+++ pkg/DESCRIPTION 2012-05-06 20:30:48 UTC (rev 268)
@@ -1,7 +1,7 @@
Package: analogue
Type: Package
Title: Analogue and weighted averaging methods for palaeoecology
-Version: 0.9-4
+Version: 0.9-5
Date: $Date$
Depends: R (>= 2.15.0), stats, graphics, vegan (>= 1.17-12), lattice, grid,
MASS, princurve, mgcv
Modified: pkg/R/Stratiplot.R
===================================================================
--- pkg/R/Stratiplot.R 2012-05-04 13:10:44 UTC (rev 267)
+++ pkg/R/Stratiplot.R 2012-05-06 20:30:48 UTC (rev 268)
@@ -75,8 +75,8 @@
stop("Ambiguous 'length(y)';\nmust be equal to 'nrow(x)' or\n'nrow(x) / number of species'.")
}
## plot parameters
- maxy <- max(y)
- miny <- min(y)
+ maxy <- max(y, na.rm = TRUE)
+ miny <- min(y, na.rm = TRUE)
## add padYlim * range as per base graphics
padY <- 0.01
if(missing(ylim)) {
@@ -85,8 +85,8 @@
ylim <- c(miny - (padY * diffy), maxy + (padY * diffy))
} else {
## should these be ylim[1] and ylim[2] ???
- minLim <- min(ylim)
- maxLim <- max(ylim)
+ minLim <- min(ylim, na.rm = TRUE)
+ maxLim <- max(ylim, na.rm = TRUE)
## add padY * range as per base graphics
diffy <- abs(diff(c(minLim, maxLim)))
ylim <- if(minLim > maxLim)
@@ -110,13 +110,14 @@
stop("Ambiguous entry in 'varTypes'.\nMust be one of \"relative\", or \"absolute\"")
## compute max abundances per relative column, which is used
## to scale the panel widths layout.widths parameter)
- max.abun <- sapply(x, function(x) round(max(x), 1), USE.NAMES = FALSE)
+ max.abun <- sapply(x, function(x) round(max(x, na.rm = TRUE), 1),
+ USE.NAMES = FALSE)
## absolute panels should be set to absoluteSize of max.abun
panelWidths <- max.abun
ABS <- which(varTypes == "absolute")
REL <- which(varTypes == "relative")
if(any(REL)) {
- panelWidths[ABS] <- absoluteSize * max(max.abun[REL])
+ panelWidths[ABS] <- absoluteSize * max(max.abun[REL], na.rm = TRUE)
} else {
panelWidths[ABS] <- absoluteSize
}
@@ -124,8 +125,8 @@
xlimits <- lapply(max.abun * 1.05, function(x) c(0, x))
if(any(ABS)) {
## but need any "absolute" panels setting to +/- 0.05(range)
- min.vars <- sapply(x[ABS], min, USE.NAMES = FALSE)
- max.vars <- sapply(x[ABS], max, USE.NAMES = FALSE)
+ min.vars <- sapply(x[ABS], min, na.rm = TRUE, USE.NAMES = FALSE)
+ max.vars <- sapply(x[ABS], max, na.rm = TRUE, USE.NAMES = FALSE)
ranges <- (0.04 * (max.vars - min.vars))
xlimits[ABS] <- as.list(data.frame(t(cbind(min.vars - ranges,
max.vars + ranges))))
@@ -133,7 +134,8 @@
## scales in xyplot call
scales <- list(cex = 0.75, tck = 0.75,
y = list(axs = "r", limits = ylim),
- x = list(axs = "r", rot = 45, relation = "free", limits = xlimits))
+ x = list(axs = "r", rot = 45, relation = "free",
+ limits = xlimits))
par.strip.text <- list(cex = 0.75)
str.max <- 1
if(!isTRUE(strip)) {
@@ -142,7 +144,9 @@
convertWidth(grobWidth(textGrob(x, gp = gp)), "lines",
valueOnly = TRUE)
}
- str.max <- max(sapply(levels(sx$ind), convWidth, gp, USE.NAMES = FALSE))
+ str.max <- max(sapply(levels(sx$ind), convWidth, gp,
+ USE.NAMES = FALSE),
+ na.rm = TRUE)
str.max <- ceiling(str.max) + topPad
}
## Legend specification for Zones
Modified: pkg/R/Stratiplot.formula.R
===================================================================
--- pkg/R/Stratiplot.formula.R 2012-05-04 13:10:44 UTC (rev 267)
+++ pkg/R/Stratiplot.formula.R 2012-05-06 20:30:48 UTC (rev 268)
@@ -1,4 +1,5 @@
-`Stratiplot.formula` <- function(formula, data, subset, na.action,
+`Stratiplot.formula` <- function(formula, data, subset,
+ na.action = "na.pass",
type = "l", ylab = NULL, xlab = "",
pages = 1, ...) {
cl <- match.call()
@@ -8,6 +9,8 @@
mf <- mf[c(1L, m)]
mf$drop.unused.levels <- TRUE
mf[[1L]] <- as.name("model.frame")
+ ## force eval of the na.action argument default
+ mf$na.action <- substitute(na.action)
mf <- eval(mf, parent.frame())
mt <- attr(mf, "terms")
y <- model.response(mf, "numeric")
Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog 2012-05-04 13:10:44 UTC (rev 267)
+++ pkg/inst/ChangeLog 2012-05-06 20:30:48 UTC (rev 268)
@@ -1,5 +1,17 @@
analogue Change Log
+Version 0.9-5
+
+ * Stratiplot: the formula interface was stripping rows with NAs.
+ This wasn't intended but was the result of not implementing all
+ of the standard non-standard evaluation idiom used by many of R's
+ modelling functions.
+
+ This is now fixed and the default for the `na.action` argument
+ has been changed to `"na.pass"`.
+
+ The default `Stratiplot()` method was working as expected.
+
Version 0.9-4
* logitreg: the returned object has changed. The list of logistic
Modified: pkg/man/Stratiplot.Rd
===================================================================
--- pkg/man/Stratiplot.Rd 2012-05-04 13:10:44 UTC (rev 267)
+++ pkg/man/Stratiplot.Rd 2012-05-06 20:30:48 UTC (rev 268)
@@ -19,7 +19,8 @@
varTypes = "relative", absoluteSize = 0.5,
zoneNames = NULL, drawLegend = TRUE, \dots)
-\method{Stratiplot}{formula}(formula, data, subset, na.action, type = "l",
+\method{Stratiplot}{formula}(formula, data, subset,
+ na.action = "na.pass", type = "l",
ylab = NULL, xlab = "", pages = 1, \dots)
}
%- maybe also 'usage' for other objects documented here.
@@ -44,11 +45,8 @@
\item{subset}{an optional vector specifying a subset of observations
to be used in the fitting process.}
\item{na.action}{a function which indicates what should happen when
- the data contain \code{NA}s. The default is set by the \code{na.action}
- setting of \code{\link{options}}, and is \code{na.fail} if that is
- unset. The \sQuote{factory-fresh} default is \code{na.omit}. Another
- possible value is \code{NULL}, no action. Value \code{na.exclude} can be
- useful.}
+ the data contain \code{NA}s. The default is \code{"na.pass"} which
+ results in \code{NA} being passed on to the plotting functions.}
\item{ylab, xlab}{the x- and y-axis labels.}
\item{pages}{numeric; the number of pages to draw the plot over. May
be useful for data sets with many species.}
@@ -113,11 +111,20 @@
standard, notation for formulae apply, such as model formulae used in
\code{\link{lm}}.
+ The default for argument \code{na.action} is \code{"na.pass"}, which
+ results in any \code{NA} values being passed on to the plotting
+ code. This allows for plotting of proxies that been measured on
+ different levels of the stratigraphy. Should you wish to have
+ \code{NA} removed from the data before plotting, use \code{na.action =
+ "na.omit"}, though do note this will remove all rows where any
+ column/variable takes the value \code{NA}. See Examples for an
+ illustration of these two techniques.
+
Note that \code{formula} is \strong{not} passed on to
- \code{\link[lattice]{xyplot}}. Instead, the formula is parsed and evaluated
- within \code{Stratiplot} and an appropriate data structure formed to
- facilitate plotting via \code{\link[lattice]{xyplot}}. As such, the special
- features of \pkg{Lattice} formulae cannot be used.
+ \code{\link[lattice]{xyplot}}. Instead, the formula is parsed and
+ evaluated within \code{Stratiplot} and an appropriate data structure
+ formed to facilitate plotting via \code{\link[lattice]{xyplot}}. As
+ such, the special features of \pkg{Lattice} formulae cannot be used.
If zones are drawn on the stratigraphic plot, the \code{zoneNames}
argument can be used to supply a set of names with which to label the
@@ -187,6 +194,16 @@
(plt <- Stratiplot(Depths ~ O.univ + G.ruber + G.tenel + G.pacR,
data = V12.122, type = c("poly","g"),
zones = Zones, zoneNames = ""))
+
+## Show illustration of NA handling
+set.seed(42)
+dat <- data.frame(Depth = 1:20, LOI = runif(20), TC = NA)
+dat <- within(dat, TC[sample(20, 10)] <- runif(10))
+## default is 'na.action = "na.pass"'
+(Stratiplot(Depth ~ LOI + TC, data = dat, type = c("l","p")))
+## to remove rows with NA, use 'na.action = "na.omit"'
+(Stratiplot(Depth ~ LOI + TC, data = dat, type = c("l","p"),
+ na.action = "na.omit"))
}
% Add one or more standard keywords, see file 'KEYWORDS' in the
% R documentation directory.
Modified: pkg/tests/Examples/analogue-Ex.Rout.save
===================================================================
--- pkg/tests/Examples/analogue-Ex.Rout.save 2012-05-04 13:10:44 UTC (rev 267)
+++ pkg/tests/Examples/analogue-Ex.Rout.save 2012-05-06 20:30:48 UTC (rev 268)
@@ -1,5 +1,5 @@
-R version 2.15.0 Patched (2012-04-18 r59085) -- "Easter Beagle"
+R version 2.15.0 Patched (2012-04-14 r59019) -- "Easter Beagle"
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-unknown-linux-gnu (64-bit)
@@ -31,7 +31,7 @@
Loading required package: princurve
Loading required package: mgcv
This is mgcv 1.7-13. For overview type 'help("mgcv-package")'.
-This is analogue 0.9-4
+This is analogue 0.9-5
>
> assign(".oldSearch", search(), pos = 'CheckExEnv')
> cleanEx()
@@ -293,8 +293,18 @@
+ data = V12.122, type = c("poly","g"),
+ zones = Zones, zoneNames = ""))
>
+> ## Show illustration of NA handling
+> set.seed(42)
+> dat <- data.frame(Depth = 1:20, LOI = runif(20), TC = NA)
+> dat <- within(dat, TC[sample(20, 10)] <- runif(10))
+> ## default is 'na.action = "na.pass"'
+> (Stratiplot(Depth ~ LOI + TC, data = dat, type = c("l","p")))
+> ## to remove rows with NA, use 'na.action = "na.omit"'
+> (Stratiplot(Depth ~ LOI + TC, data = dat, type = c("l","p"),
++ na.action = "na.omit"))
>
>
+>
> cleanEx()
> nameEx("abernethy")
> ### * abernethy
@@ -7412,7 +7422,7 @@
> ### * <FOOTER>
> ###
> cat("Time elapsed: ", proc.time() - get("ptime", pos = 'CheckExEnv'),"\n")
-Time elapsed: 30.227 0.536 30.769 0 0
+Time elapsed: 18.804 0.233 19.688 0 0
> grDevices::dev.off()
null device
1
More information about the Analogue-commits
mailing list