@@ -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
6869error_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}
0 commit comments