Skip to content

Commit

Permalink
Merge tag 'v3.0.1' into f-invariants
Browse files Browse the repository at this point in the history
tibble 3.0.1

- `[<-.tbl_df()` coerces matrices to data frames (#762).

- Use delayed import for cli to work around unload problems in downstream packages (#754).

- More soft-deprecation warnings are actually visible.

- If `.name_repair` is a function, no repair messages are shown (#763).

- Remove superseded signal for `as_tibble.list()`, because `as_tibble_row()` only works for size 1.

- `as_tibble(validate = )` now always triggers a deprecation warning.

- Subsetting and subassignment of rows with one-column matrices work again, with a deprecation warning (#760).

- Attempts to update a tibble row with an atomic vector give a clearer error message. Recycling message for subassignment appears only if target size is != 1.

- Tweak title of "Invariants" vignette.
  • Loading branch information
krlmlr committed Feb 25, 2021
2 parents 64c81ca + 85cd814 commit bee45d7
Show file tree
Hide file tree
Showing 29 changed files with 661 additions and 137 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tibble
Title: Simple Data Frames
Version: 3.0.0
Version: 3.0.1
Authors@R:
c(person(given = "Kirill",
family = "M\u00fcller",
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ exportClasses(tbl_df)
import(ellipsis)
import(lifecycle)
import(rlang)
importFrom(cli,cat_line)
importFrom(cli,symbol)
importFrom(magrittr,"%>%")
importFrom(methods,setOldClass)
importFrom(pillar,is_vector_s3)
Expand Down
29 changes: 29 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# tibble 3.0.1

## Compatibility fixes

- `[<-.tbl_df()` coerces matrices to data frames (#762).

- Use delayed import for cli to work around unload problems in downstream packages (#754).


## Bug fixes

- More soft-deprecation warnings are actually visible.

- If `.name_repair` is a function, no repair messages are shown (#763).

- Remove superseded signal for `as_tibble.list()`, because `as_tibble_row()` only works for size 1.


## Enhancements

- `as_tibble(validate = )` now always triggers a deprecation warning.

- Subsetting and subassignment of rows with one-column matrices work again, with a deprecation warning (#760).

- Attempts to update a tibble row with an atomic vector give a clearer error message. Recycling message for subassignment appears only if target size is != 1.

- Tweak title of "Invariants" vignette.


# tibble 3.0.0

## Major breaking changes
Expand Down
24 changes: 12 additions & 12 deletions R/as_tibble.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ as_tibble.data.frame <- function(x, validate = NULL, ...,
.name_repair = c("check_unique", "unique", "universal", "minimal"),
rownames = pkgconfig::get_config("tibble::rownames", NULL)) {

.name_repair <- compat_name_repair(.name_repair, validate)
.name_repair <- compat_name_repair(.name_repair, validate, missing(.name_repair))

old_rownames <- raw_rownames(x)
if (is.null(.rows)) {
Expand Down Expand Up @@ -97,10 +97,7 @@ as_tibble.data.frame <- function(x, validate = NULL, ...,
as_tibble.list <- function(x, validate = NULL, ..., .rows = NULL,
.name_repair = c("check_unique", "unique", "universal", "minimal")) {

signal_superseded("3.0.0", "as_tibble(x = 'can\\'t be a list')",
"as_tibble_row()")

.name_repair <- compat_name_repair(.name_repair, validate)
.name_repair <- compat_name_repair(.name_repair, validate, missing(.name_repair))

lst_to_tibble(x, .rows, .name_repair, col_lengths(x))
}
Expand All @@ -112,18 +109,21 @@ lst_to_tibble <- function(x, .rows, .name_repair, lengths = NULL) {
recycle_columns(x, .rows, lengths)
}

compat_name_repair <- function(.name_repair, validate) {
compat_name_repair <- function(.name_repair, validate, .missing_name_repair) {
if (is.null(validate)) return(.name_repair)

name_repair <- if (isTRUE(validate)) "check_unique" else "minimal"

if (!has_length(.name_repair, 1)) {
deprecate_soft("3.0.0", "tibble::as_tibble(validate = )", "as_tibble(.name_repair =)")
} else if (.name_repair != name_repair) {
warn("`.name_repair` takes precedence over the deprecated `validate` argument argument in `as_tibble()`.")
return(.name_repair)
if (!.missing_name_repair) {
name_repair <- .name_repair
} else if (isTRUE(validate)) {
name_repair <- "check_unique"
} else {
name_repair <- "minimal"
}

deprecate_soft("2.0.0", "tibble::as_tibble(validate = )", "as_tibble(.name_repair =)",
env = foreign_caller_env())

name_repair
}

Expand Down
12 changes: 12 additions & 0 deletions R/compat-lifecycle.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,16 @@ with_lifecycle_errors <- function(expr) {
# Enable once signal_superseded() reaches stable state
signal_superseded <- function(...) {}

foreign_caller_env <- function(my_env = ns_env()) {
for (n in 2:10) {
caller <- caller_env(n)
if (!is_reference(env_parent(caller), my_env)) {
return(caller)
}
}

# Safety net
caller
}

# nocov end
12 changes: 6 additions & 6 deletions R/glimpse.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ glimpse.tbl <- function(x, width = NULL, ...) {
cnd_signal(error_glimpse_infinite_width())
}

cat_line("Rows: ", big_mark(nrow(x)))
cli::cat_line("Rows: ", big_mark(nrow(x)))

# this is an overestimate, but shouldn't be too expensive.
# every type needs at least three characters: "x, "
rows <- as.integer(width / 3)
df <- as.data.frame(head(x, rows))
cat_line("Columns: ", big_mark(ncol(df)))
cli::cat_line("Columns: ", big_mark(ncol(df)))

summary <- tbl_sum(x)
brief_summary <- summary[-1]

if (has_length(brief_summary)) {
cat_line(names(brief_summary), ": ", brief_summary)
cli::cat_line(names(brief_summary), ": ", brief_summary)
}

if (ncol(df) == 0) return(invisible(x))
Expand All @@ -70,7 +70,7 @@ glimpse.tbl <- function(x, width = NULL, ...) {
formatted <- map_chr(df, function(x) collapse(format_v(x)))
truncated <- str_trunc(formatted, data_width)

cat_line(var_names, truncated)
cli::cat_line(var_names, truncated)
invisible(x)
}

Expand All @@ -87,12 +87,12 @@ glimpse.default <- function(x, width = NULL, max.level = 3, ...) {
str_trunc <- function(x, max_width) {
width <- nchar(x)

nchar_ellipsis <- nchar_width(symbol$ellipsis)
nchar_ellipsis <- nchar_width(cli::symbol$ellipsis)

for (i in seq_along(x)) {
if (width[i] <= max_width[i]) next

x[i] <- paste0(substr(x[i], 1, max_width[i] - nchar_ellipsis), symbol$ellipsis)
x[i] <- paste0(substr(x[i], 1, max_width[i] - nchar_ellipsis), cli::symbol$ellipsis)
}

x
Expand Down
2 changes: 1 addition & 1 deletion R/names.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repaired_names <- function(name,
details = NULL) {

subclass_name_repair_errors(name = name, details = details,
vec_as_names(name, repair = .name_repair, quiet = quiet)
vec_as_names(name, repair = .name_repair, quiet = quiet || !is_character(.name_repair))
)
}

Expand Down
8 changes: 4 additions & 4 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ NULL
#' @rdname formatting
#' @export
print.tbl <- function(x, ..., n = NULL, width = NULL, n_extra = NULL) {
cat_line(format(x, ..., n = n, width = width, n_extra = n_extra))
cli::cat_line(format(x, ..., n = n, width = width, n_extra = n_extra))
invisible(x)
}

Expand Down Expand Up @@ -197,7 +197,7 @@ print_without_body <- function(x, ...) {

#' @export
print.trunc_mat <- function(x, ...) {
cat_line(format(x, ...))
cli::cat_line(format(x, ...))
invisible(x)
}

Expand Down Expand Up @@ -251,7 +251,7 @@ format_extra_vars <- function(extra_cols) {
if (is.na(extra_cols[1])) return("")

if (anyNA(extra_cols)) {
extra_cols <- c(extra_cols[!is.na(extra_cols)], symbol$ellipsis)
extra_cols <- c(extra_cols[!is.na(extra_cols)], cli::symbol$ellipsis)
}

paste0(": ", collapse(extra_cols))
Expand All @@ -264,7 +264,7 @@ format_comment <- function(x, width) {

pre_dots <- function(x) {
if (length(x) > 0) {
paste0(symbol$ellipsis, " ", x)
paste0(cli::symbol$ellipsis, " ", x)
} else {
character()
}
Expand Down
Loading

0 comments on commit bee45d7

Please sign in to comment.