[med-svn] [r-cran-scales] 01/07: Imported Upstream version 0.4.1

Andreas Tille tille at debian.org
Mon Nov 14 09:01:47 UTC 2016


This is an automated email from the git hooks/post-receive script.

tille pushed a commit to branch master
in repository r-cran-scales.

commit 63880bf6bad69eb169aad167e43575266ea567e3
Author: Andreas Tille <tille at debian.org>
Date:   Mon Nov 14 09:46:14 2016 +0100

    Imported Upstream version 0.4.1
---
 DESCRIPTION                           |   8 +++---
 LICENSE                               |   2 +-
 MD5                                   |  29 +++++++++++---------
 NAMESPACE                             |   1 +
 NEWS.md                               |   9 +++++++
 R/RcppExports.R                       |   2 +-
 R/breaks.r                            |   8 +++++-
 R/scale-discrete.r                    |  21 +++++++++------
 R/trans-date.r                        |  49 +++++++++++++++++++++++++++++++++-
 README.md                             |   2 +-
 build/partial.rdb                     | Bin 8415 -> 7869 bytes
 man/hms_trans.Rd                      |  21 +++++++++++++++
 man/time_trans.Rd                     |   4 +--
 man/train_discrete.Rd                 |   4 ++-
 src/RcppExports.cpp                   |  26 +++++++++---------
 tests/testthat/test-breaks-extended.R |   9 +++++++
 tests/testthat/test-discrete.R        |  22 +++++++++++++++
 17 files changed, 171 insertions(+), 46 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index 59f7157..7b2340a 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,5 +1,5 @@
 Package: scales
-Version: 0.4.0
+Version: 0.4.1
 Authors at R: c(
     person("Hadley", "Wickham", , "hadley at rstudio.com", c("aut", "cre")),
     person("RStudio", role = "cph")
@@ -14,14 +14,14 @@ Depends: R (>= 2.13)
 Imports: RColorBrewer, dichromat, plyr, munsell (>= 0.2), labeling,
         methods, Rcpp
 LinkingTo: Rcpp
-Suggests: testthat (>= 0.8), covr
+Suggests: testthat (>= 0.8), covr, hms
 License: MIT + file LICENSE
 LazyLoad: yes
 RoxygenNote: 5.0.1
 NeedsCompilation: yes
-Packaged: 2016-02-26 13:10:16 UTC; hadley
+Packaged: 2016-11-08 19:11:18 UTC; hadley
 Author: Hadley Wickham [aut, cre],
   RStudio [cph]
 Maintainer: Hadley Wickham <hadley at rstudio.com>
 Repository: CRAN
-Date/Publication: 2016-02-26 15:45:07
+Date/Publication: 2016-11-09 18:28:56
diff --git a/LICENSE b/LICENSE
index 0b0b02e..267ea46 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,2 +1,2 @@
-YEAR: 2010-2014
+YEAR: 2010-2016
 COPYRIGHT HOLDER: Hadley Wickham
diff --git a/MD5 b/MD5
index 1408bdb..d162f92 100644
--- a/MD5
+++ b/MD5
@@ -1,10 +1,10 @@
-4e5466c6e09654bf89b86e6fbf12288f *DESCRIPTION
-42d91d5ce1f6db25d653397ec9da4f25 *LICENSE
-c7f322e3489424135cb779bb418828f2 *NAMESPACE
-56a8e05d6e6259c14b1f140ef0c96e16 *NEWS.md
-ee154387df2488852decb38c14e4c697 *R/RcppExports.R
+c536e7133a4fa851a6b4ac8e4bd14a15 *DESCRIPTION
+5a2ffc012eac074809a07ea440f872a8 *LICENSE
+be44277821c49763aa25b83f432558d1 *NAMESPACE
+3136bda62246a3b53b0aa4a5d99ab225 *NEWS.md
+0d76afc3c33539e2dc7e7cc8be391b61 *R/RcppExports.R
 b11eaa73b921a7f0ca0b9ce412d516c8 *R/bounds.r
-079b8af0d7acb058149e54824572af5a *R/breaks.r
+5dd1522b6c00411c8633cd8715a1b82b *R/breaks.r
 6c5942a0484c6b218a1c0b10405ac1cb *R/colour-manip.r
 4a57e7d2f12a3e7aa60e8e09b0a70f66 *R/colour-mapping.r
 2bfecd87cf7c8abc88ca53b3e1f1b31c *R/date-time.r
@@ -24,13 +24,13 @@ d6b7f3fb2fa5b7e87e6fe15d2869d112 *R/pal-manual.r
 58a8a345646e7034a6558e481defc8d6 *R/pal-shape.r
 6c4b15dde8f951ed9b35431756af8cb8 *R/range.r
 abfb1b0f1687bcdc75a9e524ce9b53d1 *R/scale-continuous.r
-a3c1aeb6e357edf1b89db85eab5ef8e3 *R/scale-discrete.r
+589b692ac75251c106e363ede654a0e5 *R/scale-discrete.r
 9637a3d24c3c74a814043f55e6591fd9 *R/scales.r
-fc31d25bce46ab8166e6b21a7601622e *R/trans-date.r
+77efc0b51a13061ab72f0a8e5b2cf197 *R/trans-date.r
 3f1ec156f1cb24f09643e4d02b68d393 *R/trans-numeric.r
 62abc8fd73c997d6e5e2312681b21086 *R/trans.r
-a9c0a08ac634745398cca9316fddd656 *README.md
-1b5b21a66e1649d50a3938fb6195d253 *build/partial.rdb
+1386600336f4bc1d5c4afd74fd7e0f4d *README.md
+c0df82949b2d936e58e8cf174eeca40e *build/partial.rdb
 9cebb6e1cc6446e15fb87de481b439b5 *man/Range-class.Rd
 cf7164e82a4551cd5b80b42025724922 *man/abs_area.Rd
 96882bfa6056c0ea536a068734ffee38 *man/alpha.Rd
@@ -62,6 +62,7 @@ d0783e1c6cbc8d00b8e149ff46cc2a30 *man/extended_breaks.Rd
 ae1ce88897cf6c70bee1d889cd028190 *man/fullseq.Rd
 e2d157eb9a85701dc727829115d3cc8a *man/gradient_n_pal.Rd
 8789d74a00daa4b600f205a9ff150ef0 *man/grey_pal.Rd
+ce44f002c4ceda67dffba83725c06ee9 *man/hms_trans.Rd
 ac05a22cba58a6004560d7faa1e089fd *man/hue_pal.Rd
 3a183825c2e46c22ea9f738be7c4e2cd *man/identity_pal.Rd
 334a28ff9d31a4c4bafd637ab22cebf3 *man/identity_trans.Rd
@@ -92,9 +93,9 @@ cbc7b40e6922f8d7d3ded0e7f79d22b0 *man/show_col.Rd
 f5097c06dadbc32103b01a846899f6b1 *man/sqrt_trans.Rd
 0376ff9300898a3cc3d19b4735bbd447 *man/squish.Rd
 70f53a5242b480a25411d156f5fbf24a *man/squish_infinite.Rd
-b2e178a8fa23f97077d1edf192c062c9 *man/time_trans.Rd
+192635ddd9b1a2ff6cd0a64447127210 *man/time_trans.Rd
 2e9b19fddb8f762acbd357759f77049c *man/train_continuous.Rd
-19d3d917fa2d64d71ddb31f08af3abe5 *man/train_discrete.Rd
+311128aaca1b09b5eb4858fc0b8880c4 *man/train_discrete.Rd
 17078f916904432680cea7e716d65cae *man/trans_breaks.Rd
 4a9b85fe979a0ec1ca40cdcd1555f73a *man/trans_format.Rd
 aac3ecd802efcede4a24a1735d6520ef *man/trans_new.Rd
@@ -102,14 +103,16 @@ a4c05123a59924a6b3e9bc02ee5c8bbe *man/trans_range.Rd
 5f0cade40a6995b50a1d1fd969b4764d *man/unit_format.Rd
 04e34ca3cedbb591e96244b0068dd6ea *man/wrap_format.Rd
 3086e5a29c13333160634a6b8147ea18 *man/zero_range.Rd
-26153fe9ba8cc9c1db5c380f9b68ddd6 *src/RcppExports.cpp
+f3983f4241cd06de6427edb3e53a3ecb *src/RcppExports.cpp
 50b694b150f1cc631e68e0c471b1737b *src/colors.cpp
 1bc97669868c55fc86b10bffb2010b63 *tests/testthat.R
 9b1f7ff67006d13e255f222feba5ee9e *tests/testthat/test-alpha.r
 210d4b72f91809cb8c82a36d60eff279 *tests/testthat/test-bounds.r
+9d3de74dea77f40ad053834c04b824be *tests/testthat/test-breaks-extended.R
 b5bb7a6051319394602be12701d8b845 *tests/testthat/test-breaks-log.r
 361eca6c9ef2ec2361364c81ff4a39cc *tests/testthat/test-colors.r
 fa5466f6b3cf5c5e7dd187b32c049408 *tests/testthat/test-colour-ramp.R
+1251432e702c697a211f0117e340051e *tests/testthat/test-discrete.R
 69eb75b4b1eca96bf1b34171b9e47056 *tests/testthat/test-formatter.r
 ce76ff71a20a24fa15228b440fdaa092 *tests/testthat/test-manual-pal.R
 0d20e9d3700f281822fcb193c9b5353d *tests/testthat/test-range.r
diff --git a/NAMESPACE b/NAMESPACE
index 729ee5c..9dafe0e 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -41,6 +41,7 @@ export(format_format)
 export(fullseq)
 export(gradient_n_pal)
 export(grey_pal)
+export(hms_trans)
 export(hue_pal)
 export(identity_pal)
 export(identity_trans)
diff --git a/NEWS.md b/NEWS.md
index 11c459d..4b135f0 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,12 @@
+# scales 0.4.1
+
+* `extended_breaks()` no longer fails on pathological inputs
+
+* New `hms_trans()` for transforming hms time vectors.
+
+* `train_discrete()` gets a new `na.rm` argument which controls whether
+  `NA`s are preserved or dropped.
+
 # scales 0.4.0
 
 * Switched from `NEWS` to `NEWS.md`
diff --git a/R/RcppExports.R b/R/RcppExports.R
index ca72a2f..c749b81 100644
--- a/R/RcppExports.R
+++ b/R/RcppExports.R
@@ -1,4 +1,4 @@
-# This file was generated by Rcpp::compileAttributes
+# Generated by using Rcpp::compileAttributes() -> do not edit by hand
 # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
 
 doColorRamp <- function(colors, x, alpha, naColor) {
diff --git a/R/breaks.r b/R/breaks.r
index 361a73d..2e4e701 100644
--- a/R/breaks.r
+++ b/R/breaks.r
@@ -32,7 +32,13 @@ pretty_breaks <- function(n = 5, ...) {
 #' extended_breaks()(1:100)
 extended_breaks <- function(n = 5, ...) {
   function(x) {
-    labeling::extended(min(x), max(x), n, only.loose = FALSE, ...)
+    x <- x[is.finite(x)]
+    if (length(x) == 0) {
+      return(numeric())
+    }
+
+    rng <- range(x)
+    labeling::extended(rng[1], rng[2], n, only.loose = FALSE, ...)
   }
 }
 
diff --git a/R/scale-discrete.r b/R/scale-discrete.r
index 99cc0e7..bd0ff3f 100644
--- a/R/scale-discrete.r
+++ b/R/scale-discrete.r
@@ -17,20 +17,21 @@ dscale <- function(x, palette, na.value = NA) {
 #' @param new New data to add to scale
 #' @param existing Optional existing scale to update
 #' @param drop \code{TRUE}, will drop factor levels not associated with data
+#' @param na.rm If \code{TRUE}, will remove missing values
 #' @export
-train_discrete <- function(new, existing = NULL, drop = FALSE) {
+train_discrete <- function(new, existing = NULL, drop = FALSE, na.rm = FALSE) {
   if (is.null(new)) return(existing)
 
   if (!is.discrete(new)) {
     stop("Continuous value supplied to discrete scale", call. = FALSE)
   }
-  discrete_range(existing, new, drop = drop)
+  discrete_range(existing, new, drop = drop, na.rm = na.rm)
 }
 
-discrete_range <- function(old, new, drop = FALSE) {
-  new <- clevels(new, drop = drop)
+discrete_range <- function(old, new, drop = FALSE, na.rm = FALSE) {
+  new <- clevels(new, drop = drop, na.rm = na.rm)
   if (is.null(old)) return(new)
-  if (!is.character(old)) old <- clevels(old)
+  if (!is.character(old)) old <- clevels(old, na.rm = na.rm)
 
   new_levels <- setdiff(new, as.character(old))
 
@@ -42,18 +43,22 @@ discrete_range <- function(old, new, drop = FALSE) {
   sort(c(old, new_levels))
 }
 
-clevels <- function(x, drop = FALSE) {
+clevels <- function(x, drop = FALSE, na.rm = FALSE) {
   if (is.null(x)) {
     character()
   } else if (is.factor(x)) {
     if (drop) x <- factor(x)
 
     values <- levels(x)
-    if (any(is.na(x))) values <- c(values, NA)
+    if (na.rm) {
+      values <- values[!is.na(values)]
+    } else if (any(is.na(x))) {
+      values <- c(values, NA)
+    }
 
     values
   } else {
-    sort(unique(x))
+    sort(unique(x), na.last = if (na.rm) NA else TRUE)
   }
 }
 
diff --git a/R/trans-date.r b/R/trans-date.r
index 1fd9c35..64c87d6 100644
--- a/R/trans-date.r
+++ b/R/trans-date.r
@@ -20,7 +20,7 @@ from_date <- function(x) {
   structure(as.numeric(x), names = names(x))
 }
 
-#' Transformation for times (class POSIXt).
+#' Transformation for date-times (class POSIXt).
 #'
 #' @param tz Optionally supply the time zone.  If \code{NULL}, the default,
 #'   the time zone will be extracted from first input with a non-null tz.
@@ -52,6 +52,53 @@ time_trans <- function(tz = NULL) {
   trans_new("time", "from_time", "to_time", breaks = pretty_breaks())
 }
 
+#' Transformation for times (class hms).
+#'
+#' @export
+#' @examples
+#' if (require("hms")) {
+#' hms <- round(runif(10) * 86400)
+#' t <- hms_trans()
+#' t$transform(hms)
+#' t$inverse(t$transform(hms))
+#' t$breaks(hms)
+#' }
+hms_trans <- function() {
+  trans_new(
+    "hms",
+    transform = function(x) {
+      structure(as.numeric(x), names = names(x))
+    },
+    inverse = hms::as.hms,
+    breaks = time_breaks()
+  )
+}
+
+time_breaks <- function(n = 5) {
+  function(x) {
+    rng <- as.numeric(range(x))
+    diff <- rng[2] - rng[1]
+
+    if (diff <= 2 * 60) {
+      scale <- 1
+    } else if (diff <= 2 * 3600) {
+      scale <- 60
+    } else if (diff <= 2 * 86400) {
+      scale <- 3600
+    } else {
+      scale <- 86400
+    }
+
+    rng <- rng / scale
+    breaks <- labeling::extended(
+      rng[1], rng[2], n,
+      Q = c(1, 2, 1.5, 4, 3),
+      only.loose = FALSE
+    )
+    hms::as.hms(breaks * scale)
+  }
+}
+
 
 #' Regularly spaced dates.
 #'
diff --git a/README.md b/README.md
index 3d0344f..2bf435e 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
 
 [![Build Status](https://travis-ci.org/hadley/scales.png?branch=master)](https://travis-ci.org/hadley/scales)
 [![Coverage Status](https://img.shields.io/codecov/c/github/hadley/scales/master.svg)](https://codecov.io/github/hadley/scales?branch=master)
-[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/scales)](http://cran.r-project.org/package=scales)
+[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/scales)](https://cran.r-project.org/package=scales)
 
 One of the most difficult parts of any graphics package is scaling, converting from data values to perceptual properties. The inverse of scaling, making guides (legends and axes) that can be used to read the graph, is often even harder! The idea of the `scales` package is to implement scales in a way that is graphics system agnostic, so that everyone can benefit by pooling knowledge and resources about this tricky topic.
 
diff --git a/build/partial.rdb b/build/partial.rdb
index 22717a9..5f59257 100644
Binary files a/build/partial.rdb and b/build/partial.rdb differ
diff --git a/man/hms_trans.Rd b/man/hms_trans.Rd
new file mode 100644
index 0000000..9fd3035
--- /dev/null
+++ b/man/hms_trans.Rd
@@ -0,0 +1,21 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/trans-date.r
+\name{hms_trans}
+\alias{hms_trans}
+\title{Transformation for times (class hms).}
+\usage{
+hms_trans()
+}
+\description{
+Transformation for times (class hms).
+}
+\examples{
+if (require("hms")) {
+hms <- round(runif(10) * 86400)
+t <- hms_trans()
+t$transform(hms)
+t$inverse(t$transform(hms))
+t$breaks(hms)
+}
+}
+
diff --git a/man/time_trans.Rd b/man/time_trans.Rd
index 35daa4c..d543b62 100644
--- a/man/time_trans.Rd
+++ b/man/time_trans.Rd
@@ -2,7 +2,7 @@
 % Please edit documentation in R/trans-date.r
 \name{time_trans}
 \alias{time_trans}
-\title{Transformation for times (class POSIXt).}
+\title{Transformation for date-times (class POSIXt).}
 \usage{
 time_trans(tz = NULL)
 }
@@ -11,7 +11,7 @@ time_trans(tz = NULL)
 the time zone will be extracted from first input with a non-null tz.}
 }
 \description{
-Transformation for times (class POSIXt).
+Transformation for date-times (class POSIXt).
 }
 \examples{
 hours <- seq(ISOdate(2000,3,20, tz = ""), by = "hour", length.out = 10)
diff --git a/man/train_discrete.Rd b/man/train_discrete.Rd
index 5b97bb2..4db24cc 100644
--- a/man/train_discrete.Rd
+++ b/man/train_discrete.Rd
@@ -4,7 +4,7 @@
 \alias{train_discrete}
 \title{Train (update) a discrete scale}
 \usage{
-train_discrete(new, existing = NULL, drop = FALSE)
+train_discrete(new, existing = NULL, drop = FALSE, na.rm = FALSE)
 }
 \arguments{
 \item{new}{New data to add to scale}
@@ -12,6 +12,8 @@ train_discrete(new, existing = NULL, drop = FALSE)
 \item{existing}{Optional existing scale to update}
 
 \item{drop}{\code{TRUE}, will drop factor levels not associated with data}
+
+\item{na.rm}{If \code{TRUE}, will remove missing values}
 }
 \description{
 Train (update) a discrete scale
diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp
index 232f6c0..6bd1492 100644
--- a/src/RcppExports.cpp
+++ b/src/RcppExports.cpp
@@ -1,4 +1,4 @@
-// This file was generated by Rcpp::compileAttributes
+// Generated by using Rcpp::compileAttributes() -> do not edit by hand
 // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
 
 #include <Rcpp.h>
@@ -9,35 +9,35 @@ using namespace Rcpp;
 StringVector doColorRamp(NumericMatrix colors, NumericVector x, bool alpha, std::string naColor);
 RcppExport SEXP scales_doColorRamp(SEXP colorsSEXP, SEXP xSEXP, SEXP alphaSEXP, SEXP naColorSEXP) {
 BEGIN_RCPP
-    Rcpp::RObject __result;
-    Rcpp::RNGScope __rngScope;
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
     Rcpp::traits::input_parameter< NumericMatrix >::type colors(colorsSEXP);
     Rcpp::traits::input_parameter< NumericVector >::type x(xSEXP);
     Rcpp::traits::input_parameter< bool >::type alpha(alphaSEXP);
     Rcpp::traits::input_parameter< std::string >::type naColor(naColorSEXP);
-    __result = Rcpp::wrap(doColorRamp(colors, x, alpha, naColor));
-    return __result;
+    rcpp_result_gen = Rcpp::wrap(doColorRamp(colors, x, alpha, naColor));
+    return rcpp_result_gen;
 END_RCPP
 }
 // rgbToLab
 NumericVector rgbToLab(NumericVector rgb);
 RcppExport SEXP scales_rgbToLab(SEXP rgbSEXP) {
 BEGIN_RCPP
-    Rcpp::RObject __result;
-    Rcpp::RNGScope __rngScope;
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
     Rcpp::traits::input_parameter< NumericVector >::type rgb(rgbSEXP);
-    __result = Rcpp::wrap(rgbToLab(rgb));
-    return __result;
+    rcpp_result_gen = Rcpp::wrap(rgbToLab(rgb));
+    return rcpp_result_gen;
 END_RCPP
 }
 // rgbToXyz
 NumericVector rgbToXyz(NumericVector rgb);
 RcppExport SEXP scales_rgbToXyz(SEXP rgbSEXP) {
 BEGIN_RCPP
-    Rcpp::RObject __result;
-    Rcpp::RNGScope __rngScope;
+    Rcpp::RObject rcpp_result_gen;
+    Rcpp::RNGScope rcpp_rngScope_gen;
     Rcpp::traits::input_parameter< NumericVector >::type rgb(rgbSEXP);
-    __result = Rcpp::wrap(rgbToXyz(rgb));
-    return __result;
+    rcpp_result_gen = Rcpp::wrap(rgbToXyz(rgb));
+    return rcpp_result_gen;
 END_RCPP
 }
diff --git a/tests/testthat/test-breaks-extended.R b/tests/testthat/test-breaks-extended.R
new file mode 100644
index 0000000..2df1275
--- /dev/null
+++ b/tests/testthat/test-breaks-extended.R
@@ -0,0 +1,9 @@
+context("breaks - extended")
+
+test_that("extended breaks returns no breaks for bad inputs", {
+  breaks <- extended_breaks()
+
+  expect_equal(breaks(NA), numeric())
+  expect_equal(breaks(Inf), numeric())
+  expect_equal(breaks(NaN), numeric())
+})
diff --git a/tests/testthat/test-discrete.R b/tests/testthat/test-discrete.R
new file mode 100644
index 0000000..f663907
--- /dev/null
+++ b/tests/testthat/test-discrete.R
@@ -0,0 +1,22 @@
+context("discrete")
+
+test_that("na.rm = FALSE keeps NA", {
+  x1 <- c("a", NA)
+  x2 <- factor(x1)
+  x3 <- addNA(x2)
+
+  expect_equal(train_discrete(x1, na.rm = FALSE), c("a", NA))
+  expect_equal(train_discrete(x2, na.rm = FALSE), c("a", NA))
+  expect_equal(train_discrete(x3, na.rm = FALSE), c("a", NA))
+})
+
+
+test_that("na.rm = TRUE drops NA", {
+  x1 <- c("a", NA)
+  x2 <- factor(x1)
+  x3 <- addNA(x2)
+
+  expect_equal(train_discrete(x1, na.rm = TRUE), "a")
+  expect_equal(train_discrete(x2, na.rm = TRUE), "a")
+  expect_equal(train_discrete(x3, na.rm = TRUE), "a")
+})

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/r-cran-scales.git



More information about the debian-med-commit mailing list