Skip to content

Commit 570fefa

Browse files
committed
Merge branch 'master' into b-773-na-subassign
2 parents 22544f1 + 8994e1e commit 570fefa

38 files changed

+126
-55
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: tibble
22
Title: Simple Data Frames
3-
Version: 3.1.2.9000
3+
Version: 3.1.2.9001
44
Authors@R:
55
c(person(given = "Kirill",
66
family = "M\u00fcller",

NAMESPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export(column_to_rownames)
3838
export(data_frame)
3939
export(data_frame_)
4040
export(deframe)
41+
export(dim_desc)
4142
export(enframe)
4243
export(frame_data)
4344
export(frame_matrix)
@@ -75,6 +76,7 @@ import(rlang)
7576
importFrom(magrittr,"%>%")
7677
importFrom(methods,setOldClass)
7778
importFrom(pillar,char)
79+
importFrom(pillar,dim_desc)
7880
importFrom(pillar,glimpse)
7981
importFrom(pillar,num)
8082
importFrom(pillar,obj_sum)
@@ -95,9 +97,11 @@ importFrom(vctrs,vec_as_subscript2)
9597
importFrom(vctrs,vec_assign)
9698
importFrom(vctrs,vec_c)
9799
importFrom(vctrs,vec_is)
100+
importFrom(vctrs,vec_names2)
98101
importFrom(vctrs,vec_ptype_abbr)
99102
importFrom(vctrs,vec_rbind)
100103
importFrom(vctrs,vec_recycle)
104+
importFrom(vctrs,vec_set_names)
101105
importFrom(vctrs,vec_size)
102106
importFrom(vctrs,vec_slice)
103107
useDynLib(tibble, .registration = TRUE)

NEWS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
<!-- NEWS.md is maintained by https://cynkra.github.io/fledge, do not edit -->
22

3+
# tibble 3.1.2.9001
4+
5+
- Use `pillar::dim_desc()` (#859).
6+
- `[[<-()` supports symbols (#893).
7+
- `enframe()` and `deframe()` support arbitrary vectors (#730).
8+
- `tibble()` and `tibble_row()` ignore all columns that evaluate to `NULL`, not only those where a verbatim `NULL` is passed (#895, #900).
9+
- `new_tibble()` is now faster (#901, @mgirlich).
10+
- Establish compatibility with testthat > 3.0.3 (#896, @lionel-).
11+
12+
313
# tibble 3.1.2.9000
414

515
- Bump required versions of ellipsis and vctrs to avoid warning during package load.

R/enframe.R

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,24 @@ enframe <- function(x, name = "name", value = "value") {
2424
cnd_signal(error_enframe_value_null())
2525
}
2626

27-
if (length(dim(x)) > 1) {
28-
cnd_signal(error_enframe_has_dim(x))
27+
if (is.null(x)) {
28+
x <- logical()
2929
}
3030

31-
if (is.null(x)) x <- logical()
31+
if (!vec_is(x)) {
32+
cnd_signal(error_enframe_must_be_vector(x))
33+
}
3234

3335
if (is.null(name)) {
34-
df <- list(unname(x))
36+
df <- list(vec_set_names(x, NULL))
3537
} else if (is.null(names(x))) {
36-
df <- list(seq_along(x), x)
38+
df <- list(seq_len(vec_size(x)), x)
3739
} else {
38-
df <- list(names(x), unname(x))
40+
df <- list(vec_names2(x), vec_set_names(x, NULL))
3941
}
4042

4143
names(df) <- c(name, value)
42-
new_tibble(df, nrow = length(x))
44+
new_tibble(df, nrow = vec_size(x))
4345
}
4446

4547
#' @rdname enframe
@@ -61,14 +63,15 @@ deframe <- function(x) {
6163

6264
value <- x[[2L]]
6365
name <- x[[1L]]
64-
names(value) <- name
65-
value
66+
vec_set_names(value, as.character(name))
6667
}
6768

6869
error_enframe_value_null <- function() {
6970
tibble_error("`value` can't be NULL.")
7071
}
7172

72-
error_enframe_has_dim <- function(x) {
73-
tibble_error(paste0("`x` must not have more than one dimension. `length(dim(x))` must be zero or one, not ", length(dim(x)), "."))
73+
error_enframe_must_be_vector <- function(x) {
74+
tibble_error(paste0(
75+
"The `x` argument to `enframe()` must be a vector, not ", class(x)[[1]], "."
76+
))
7477
}

R/subsetting.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ NULL
168168
}
169169

170170
# Side effect: check scalar
171-
if (!is.vector(j) || length(j) != 1L || is.na(j) || (is.numeric(j) && j < 0) || is.logical(j)) {
172-
vectbl_as_col_location2(j, length(x) + 1L, j_arg = j_arg, assign = TRUE)
171+
if (!is.symbol(j)) {
172+
if (!is.vector(j) || length(j) != 1L || is.na(j) || (is.numeric(j) && j < 0) || is.logical(j)) {
173+
vectbl_as_col_location2(j, length(x) + 1L, j_arg = j_arg, assign = TRUE)
174+
}
173175
}
174176

175177
j <- vectbl_as_new_col_index(j, x, value, j_arg, value_arg)

R/tbl_sum.R

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ tbl_sum.tbl_df <- function(x) {
77
c("A tibble" = dim_desc(x))
88
}
99

10-
dim_desc <- function(x) {
11-
dim <- dim(x) %||% length(x)
12-
format_dim <- map_chr(dim, big_mark)
13-
paste0(format_dim, collapse = spaces_around(mult_sign()))
14-
}
10+
#' @importFrom pillar dim_desc
11+
#' @export
12+
pillar::dim_desc
1513

1614
#' @importFrom pillar obj_sum
1715
#' @export

R/tibble-package.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#' @importFrom vctrs vec_as_location vec_as_location2 vec_as_names vec_as_names_legacy vec_c
88
#' @importFrom vctrs vec_is vec_rbind vec_recycle vec_size vec_slice vec_assign
99
#' @importFrom vctrs unspecified vec_as_subscript2 num_as_location vec_ptype_abbr
10+
#' @importFrom vctrs vec_names2 vec_set_names
1011
#' @aliases NULL tibble-package
1112
#' @details
1213
#' `r lifecycle::badge("stable")`

man/reexports.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/enframe.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,46 @@
55
Error <tibble_error_enframe_value_null>
66
`value` can't be NULL.
77
Code
8-
enframe(Titanic)
9-
Error <tibble_error_enframe_has_dim>
10-
`x` must not have more than one dimension. `length(dim(x))` must be zero or one, not 4.
8+
nrow(enframe(Titanic))
9+
Output
10+
[1] 4
11+
Code
12+
enframe(Titanic)$value
13+
Output
14+
, , Age = Child, Survived = No
15+
16+
Sex
17+
Class Male Female
18+
1st 0 0
19+
2nd 0 0
20+
3rd 35 17
21+
Crew 0 0
22+
23+
, , Age = Adult, Survived = No
24+
25+
Sex
26+
Class Male Female
27+
1st 118 4
28+
2nd 154 13
29+
3rd 387 89
30+
Crew 670 3
31+
32+
, , Age = Child, Survived = Yes
33+
34+
Sex
35+
Class Male Female
36+
1st 5 1
37+
2nd 11 13
38+
3rd 13 14
39+
Crew 0 0
40+
41+
, , Age = Adult, Survived = Yes
42+
43+
Sex
44+
Class Male Female
45+
1st 57 140
46+
2nd 14 80
47+
3rd 75 76
48+
Crew 192 20
49+
1150

tests/testthat/_snaps/msg.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@
118118
<error/tibble_error_enframe_value_null>
119119
`value` can't be NULL.
120120
Code
121-
error_enframe_has_dim(Titanic)
121+
error_enframe_must_be_vector(lm(speed ~ ., cars))
122122
Output
123-
<error/tibble_error_enframe_has_dim>
124-
`x` must not have more than one dimension. `length(dim(x))` must be zero or one, not 4.
123+
<error/tibble_error_enframe_must_be_vector>
124+
The `x` argument to `enframe()` must be a vector, not lm.
125125
Code
126126
# # names
127127
error_column_names_cannot_be_empty(1, repair_hint = TRUE)

0 commit comments

Comments
 (0)