From 88f86cdd96ae1781b403ab790430d552016fdeb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Thu, 17 Mar 2016 19:05:12 +0100 Subject: [PATCH 01/13] don't need PR anymore --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index aded5b0ee..676db90cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ r: - devel r_github_packages: - - jimhester/covr#154 + - jimhester/covr after_success: - Rscript -e 'covr::codecov()' From b15609a02406c5b366f26f03f2e01f2b37acf1dc Mon Sep 17 00:00:00 2001 From: jennybc Date: Mon, 14 Mar 2016 22:23:37 -0700 Subject: [PATCH 02/13] add tests that [ does not change class --- tests/testthat/test-tbl-df.r | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/testthat/test-tbl-df.r b/tests/testthat/test-tbl-df.r index c2c017d9f..304779226 100644 --- a/tests/testthat/test-tbl-df.r +++ b/tests/testthat/test-tbl-df.r @@ -7,6 +7,13 @@ test_that("[ never drops", { expect_equal(mtcars2[, 1], mtcars2[1]) }) +test_that("[ retains class", { + mtcars2 <- tbl_df(mtcars) + expect_identical(class(mtcars2), class(mtcars2[1:5, ])) + expect_identical(class(mtcars2), class(mtcars2[, 1:5])) + expect_identical(class(mtcars2), class(mtcars2[1:5, 1:5])) +}) + test_that("[ with 0 cols creates correct row names (#656)", { zero_row <- tbl_df(iris)[, 0] expect_is(zero_row, "tbl_df") From ef9aaad1cd85cdb7555b7da36f052292f603571f Mon Sep 17 00:00:00 2001 From: hadley Date: Thu, 17 Mar 2016 17:34:19 -0500 Subject: [PATCH 03/13] Delete collate --- DESCRIPTION | 4 ---- 1 file changed, 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index dde1a278a..9cee4578e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,7 +22,3 @@ License: MIT + file LICENSE RoxygenNote: 5.0.1 LinkingTo: Rcpp VignetteBuilder: knitr -Collate: 'RcppExports.R' 'all-equal.r' 'rownames.R' 'dataframe.R' - 'frame-data.R' 'glimpse.R' 'repair-column-names.R' - 'src-local.r' 'src.r' 'tbl-df.r' 'tibble.R' 'type-sum.r' - 'utils-format.r' 'utils.r' From b050412ef09ba9a712897827a28023d7aaa60806 Mon Sep 17 00:00:00 2001 From: hadley Date: Thu, 17 Mar 2016 17:34:37 -0500 Subject: [PATCH 04/13] Tweaks to repair_names documentation. Also give the file a better name --- R/{repair-column-names.R => repair-names.R} | 21 +++++++++--------- man/repair_names.Rd | 24 ++++++++++----------- 2 files changed, 21 insertions(+), 24 deletions(-) rename R/{repair-column-names.R => repair-names.R} (67%) diff --git a/R/repair-column-names.R b/R/repair-names.R similarity index 67% rename from R/repair-column-names.R rename to R/repair-names.R index e2f9e5c1f..0f1a6cb1d 100644 --- a/R/repair-column-names.R +++ b/R/repair-names.R @@ -1,22 +1,21 @@ -#' Check validity/format of a data.frame or tbl. +#' Repair object names. #' -#' Ensure the object (e.g., tbl, data.frame or list) has legitimate and unique -#' names without leading or trailing blanks. +#' \code{repair_names} ensures its input has non-missing and +#' unique names. It also strips any leading or trailing spaces. +#' Valid names are left as is. #' -#' The function does not change any names that are correct already. -#' -#' @param x named object -#' @param prefix character, the prefix to use for new column names -#' @param sep character, a character string to separate the terms. Not -#' \code{NA_character_}. -#' @return input with reparied names +#' @param x A named vector. +#' @param prefix A string, the prefix to use for new column names. +#' @param sep A string, inserted between the column name and de-duplicating +#' number. +#' @return \code{x} with valid names. #' @export #' @examples #' repair_names(list(3, 4, 5)) # works for lists, too #' repair_names(mtcars) # a no-op #' tbl <- as_data_frame(structure(list(3, 4, 5), class = "data.frame")) #' repair_names(tbl) -repair_names <- function(x, prefix = "V", sep = "") { +repair_names <- function(x, prefix = "V", sep = "_") { if (length(x) == 0) return(x) diff --git a/man/repair_names.Rd b/man/repair_names.Rd index c58895ac4..ab5d6a5ac 100644 --- a/man/repair_names.Rd +++ b/man/repair_names.Rd @@ -1,28 +1,26 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/repair-column-names.R +% Please edit documentation in R/repair-names.R \name{repair_names} \alias{repair_names} -\title{Check validity/format of a data.frame or tbl.} +\title{Repair object names.} \usage{ -repair_names(x, prefix = "V", sep = "") +repair_names(x, prefix = "V", sep = "_") } \arguments{ -\item{x}{named object} +\item{x}{A named vector.} -\item{prefix}{character, the prefix to use for new column names} +\item{prefix}{A string, the prefix to use for new column names.} -\item{sep}{character, a character string to separate the terms. Not -\code{NA_character_}.} +\item{sep}{A string, inserted between the column name and de-duplicating +number.} } \value{ -input with reparied names +\code{x} with valid names. } \description{ -Ensure the object (e.g., tbl, data.frame or list) has legitimate and unique -names without leading or trailing blanks. -} -\details{ -The function does not change any names that are correct already. +\code{repair_names} ensures its input has non-missing and +unique names. It also strips any leading or trailing spaces. +Valid names are left as is. } \examples{ repair_names(list(3, 4, 5)) # works for lists, too From 6d887c5722a882206f02da02b407e52b614c2b5f Mon Sep 17 00:00:00 2001 From: hadley Date: Thu, 17 Mar 2016 17:36:57 -0500 Subject: [PATCH 05/13] Revert typo --- R/repair-names.R | 2 +- man/repair_names.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/repair-names.R b/R/repair-names.R index 0f1a6cb1d..9edaa5294 100644 --- a/R/repair-names.R +++ b/R/repair-names.R @@ -15,7 +15,7 @@ #' repair_names(mtcars) # a no-op #' tbl <- as_data_frame(structure(list(3, 4, 5), class = "data.frame")) #' repair_names(tbl) -repair_names <- function(x, prefix = "V", sep = "_") { +repair_names <- function(x, prefix = "V", sep = "") { if (length(x) == 0) return(x) diff --git a/man/repair_names.Rd b/man/repair_names.Rd index ab5d6a5ac..7ef434a5f 100644 --- a/man/repair_names.Rd +++ b/man/repair_names.Rd @@ -4,7 +4,7 @@ \alias{repair_names} \title{Repair object names.} \usage{ -repair_names(x, prefix = "V", sep = "_") +repair_names(x, prefix = "V", sep = "") } \arguments{ \item{x}{A named vector.} From 28c0e92c614bd6e6b208b2d481e969b92db47741 Mon Sep 17 00:00:00 2001 From: hadley Date: Thu, 17 Mar 2016 17:37:34 -0500 Subject: [PATCH 06/13] Tidy up DESCRIPTION --- DESCRIPTION | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9cee4578e..66289ee19 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,24 +1,33 @@ -Encoding: UTF-8 Package: tibble -Type: Package +Encoding: UTF-8 Version: 0.3-2 -Date: 2016-03-17 Title: Simple Data Frames Description: Provides a 'tbl_df' class that offers better checking and - printing capabilities than traditional data frames. -Authors@R: c( person("Hadley", "Wickham", , "hadley@rstudio.com", role - = "aut"), person("Romain", "Francois", , - "romain@r-enthusiasts.com", role = "aut"), person("Kirill", - "Müller", , "krlmlr+r@mailbox.org", role = c("aut", "cre")), - person("RStudio", role = "cph") ) + printing capabilities than traditional data frames. +Authors@R: c( + person("Hadley", "Wickham", , "hadley@rstudio.com", "aut"), + person("Romain", "Francois", , "romain@r-enthusiasts.com", "aut"), + person("Kirill", "Müller", , "krlmlr+r@mailbox.org", c("aut", "cre")), + person("RStudio", role = "cph") + ) URL: https://github.com/krlmlr/tibble BugReports: https://github.com/krlmlr/tibble/issues Depends: R (>= 3.1.2) -Imports: methods, assertthat, utils, lazyeval (>= 0.1.10), Rcpp -Suggests: testthat, knitr, rmarkdown, Lahman (>= 3.0.1), magrittr, - microbenchmark +Imports: + methods, + assertthat, + utils, + lazyeval (>= 0.1.10), + Rcpp +Suggests: + testthat, + knitr, + rmarkdown, + Lahman (>= 3.0.1), + magrittr, + microbenchmark +LinkingTo: Rcpp LazyData: yes License: MIT + file LICENSE RoxygenNote: 5.0.1 -LinkingTo: Rcpp VignetteBuilder: knitr From 69baa4a9a55e429a7f955ff2906ff8ca7fefa05c Mon Sep 17 00:00:00 2001 From: hadley Date: Thu, 17 Mar 2016 17:38:13 -0500 Subject: [PATCH 07/13] Build vignettes when checking locally --- tibble.Rproj | 1 - 1 file changed, 1 deletion(-) diff --git a/tibble.Rproj b/tibble.Rproj index 6fb1c1949..270314b87 100644 --- a/tibble.Rproj +++ b/tibble.Rproj @@ -18,5 +18,4 @@ StripTrailingWhitespace: Yes BuildType: Package PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source -PackageBuildArgs: --no-build-vignettes PackageRoxygenize: rd,collate,namespace From 905c4c745eaf9dde238cc42b2df1a681899a0d8c Mon Sep 17 00:00:00 2001 From: hadley Date: Thu, 17 Mar 2016 17:38:49 -0500 Subject: [PATCH 08/13] Include NEWS.md in package --- .Rbuildignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.Rbuildignore b/.Rbuildignore index d148ba836..65f611b99 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -4,7 +4,6 @@ .Rprofile inst/db man-roxygen -NEWS\.md demo/pandas ^\.httr-oauth$ ^cran-comments\.md$ From 6cfb3502708a94f0ac1e043dd946232c87820712 Mon Sep 17 00:00:00 2001 From: hadley Date: Thu, 17 Mar 2016 17:44:14 -0500 Subject: [PATCH 09/13] Only print first S4 class When used in list-columns, S4 objects only print the class name than the full class hierarchy. Fixes #33. --- R/utils-format.r | 2 +- tests/testthat/test-trunc-mat.r | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/R/utils-format.r b/R/utils-format.r index 916bf9593..bbbd7d7d9 100644 --- a/R/utils-format.r +++ b/R/utils-format.r @@ -175,7 +175,7 @@ obj_type.default <- function(x) { } else if (!isS4(x)) { paste0("") } else { - paste0("") + paste0("") } } diff --git a/tests/testthat/test-trunc-mat.r b/tests/testthat/test-trunc-mat.r index 59e68ec16..6efbd1dea 100644 --- a/tests/testthat/test-trunc-mat.r +++ b/tests/testthat/test-trunc-mat.r @@ -102,3 +102,8 @@ test_that("trunc_mat output matches known output", { knit_cacheable = TRUE) ) }) + +test_that("obj_type shows only first class name for S4", { + A <- methods::setClass("A") + expect_equal(obj_type(A), "") +}) From 3d99995ad9c39cb85af8f5569364d4a877d6743f Mon Sep 17 00:00:00 2001 From: hadley Date: Thu, 17 Mar 2016 17:48:45 -0500 Subject: [PATCH 10/13] Fall back to regular subsetting. `[[.tbl_df` now falls back to regular subsetting when used with anything other than a single string. Fixes #29 --- R/tbl-df.r | 4 ++-- tests/testthat/test-tbl-df.r | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/R/tbl-df.r b/R/tbl-df.r index 2d1bbc376..acbfe082d 100644 --- a/R/tbl-df.r +++ b/R/tbl-df.r @@ -61,13 +61,13 @@ print.tbl_df <- function(x, ..., n = NULL, width = NULL) { #' @export `[[.tbl_df` <- function(x, i, exact = TRUE) { - if (is.character(i) && !(i %in% names(x))) + if (is.character(i) && length(i) == 1L && !(i %in% names(x))) stop("Unknown name", call. = FALSE) if (!exact) { warning("exact ignored", call. = FALSE) } - .subset2(x, i) + NextMethod() } #' @export diff --git a/tests/testthat/test-tbl-df.r b/tests/testthat/test-tbl-df.r index 304779226..bb727a660 100644 --- a/tests/testthat/test-tbl-df.r +++ b/tests/testthat/test-tbl-df.r @@ -38,3 +38,9 @@ test_that("[[.tbl_df ignores exact argument",{ expect_warning(foo[["x", exact = FALSE]], "ignored") expect_identical(getElement(foo, "y"), 1:10) }) + +test_that("can use recursive indexing with [[", { + foo <- data_frame(x = list(y = 1:3, z = 4:5)) + expect_equal(foo[[c(1, 1)]], 1:3) + expect_equal(foo[[c("x", "y")]], 1:3) +}) From 046f3711a3b065f60ddf8545c34159bdd66c7108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Fri, 18 Mar 2016 08:39:28 +0100 Subject: [PATCH 11/13] bump version to 0.3-3 --- DESCRIPTION | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 66289ee19..cc2a78641 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,31 +1,20 @@ Package: tibble Encoding: UTF-8 -Version: 0.3-2 +Version: 0.3-3 Title: Simple Data Frames Description: Provides a 'tbl_df' class that offers better checking and - printing capabilities than traditional data frames. -Authors@R: c( - person("Hadley", "Wickham", , "hadley@rstudio.com", "aut"), - person("Romain", "Francois", , "romain@r-enthusiasts.com", "aut"), - person("Kirill", "Müller", , "krlmlr+r@mailbox.org", c("aut", "cre")), - person("RStudio", role = "cph") - ) + printing capabilities than traditional data frames. +Authors@R: c( person("Hadley", "Wickham", , "hadley@rstudio.com", + "aut"), person("Romain", "Francois", , + "romain@r-enthusiasts.com", "aut"), person("Kirill", "Müller", + , "krlmlr+r@mailbox.org", c("aut", "cre")), person("RStudio", + role = "cph") ) URL: https://github.com/krlmlr/tibble BugReports: https://github.com/krlmlr/tibble/issues Depends: R (>= 3.1.2) -Imports: - methods, - assertthat, - utils, - lazyeval (>= 0.1.10), - Rcpp -Suggests: - testthat, - knitr, - rmarkdown, - Lahman (>= 3.0.1), - magrittr, - microbenchmark +Imports: methods, assertthat, utils, lazyeval (>= 0.1.10), Rcpp +Suggests: testthat, knitr, rmarkdown, Lahman (>= 3.0.1), magrittr, + microbenchmark LinkingTo: Rcpp LazyData: yes License: MIT + file LICENSE From 4b6a6d1f1fe89ac3bd23bb34e4c1f16dffcedb6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Fri, 18 Mar 2016 08:40:08 +0100 Subject: [PATCH 12/13] NEWS as generated from Hadley's comments --- NEWS.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/NEWS.md b/NEWS.md index ba5a79f4a..7da8f839a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,13 @@ +Version 0.3-3 (2016-03-18) +=== + +`[[.tbl_df` now falls back to regular subsetting when used with anything other than a single string. +Fixes #29 +When used in list-columns, S4 objects only print the class name than the full class hierarchy. Fixes #33. +Also give the file a better name +add test that [ does not change class + + Version 0.3-2 (2016-03-17) === From 3cc26ebd3b6f6c98699949997753394e8b71a1cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Fri, 18 Mar 2016 08:42:11 +0100 Subject: [PATCH 13/13] edited NEWS --- NEWS.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index 7da8f839a..1da92edf8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,11 +1,10 @@ Version 0.3-3 (2016-03-18) === -`[[.tbl_df` now falls back to regular subsetting when used with anything other than a single string. -Fixes #29 -When used in list-columns, S4 objects only print the class name than the full class hierarchy. Fixes #33. -Also give the file a better name -add test that [ does not change class +- `[[.tbl_df()` now falls back to regular subsetting when used with anything other than a single string (#29). +- When used in list-columns, S4 objects only print the class name rather than the full class hierarchy (#33). +- Further cleanup for `repair_names()`. +- Add test that `[.tbl_df()` does not change class (#41, @jennybc). Version 0.3-2 (2016-03-17)