Skip to content

Commit 6c179fb

Browse files
committed
Merge branch 'master' into tbl-new-data-frame
2 parents 62397b1 + 0f7901e commit 6c179fb

File tree

6 files changed

+74
-64
lines changed

6 files changed

+74
-64
lines changed

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ importFrom(pillar,type_sum)
8686
importFrom(pkgconfig,set_config)
8787
importFrom(utils,head)
8888
importFrom(utils,tail)
89-
importFrom(vctrs,"vec_slice<-")
9089
importFrom(vctrs,new_data_frame)
9190
importFrom(vctrs,new_rcrd)
9291
importFrom(vctrs,num_as_location)

R/new.R

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ new_tibble <- function(x, ..., nrow, class = NULL, subclass = NULL) {
6060
#' equal to this value.
6161
#' (But this is not checked by the constructor).
6262
#' This takes the place of the "row.names" attribute in a data frame.
63-
if (!is_integerish(nrow, 1)) {
63+
if (is_integerish(nrow, 1)) {
64+
nrow <- as.integer(nrow)
65+
} else {
6466
cnd_signal(error_new_tibble_needs_nrow())
6567
}
6668

@@ -87,14 +89,25 @@ new_tibble <- function(x, ..., nrow, class = NULL, subclass = NULL) {
8789
#' but the names are not checked for correctness.
8890
if (length(x) == 0) {
8991
# Leaving this because creating a named list of length zero seems difficult
90-
names(x) <- character()
91-
} else if (is.null(names(x))) {
92+
args[["names"]] <- character()
93+
} else if (is.null(args[["names"]])) {
9294
cnd_signal(error_names_must_be_non_null())
9395
}
9496

95-
attr(x, "row.names") <- .set_row_names(nrow)
96-
class(x) <- c(class[!class %in% tibble_class], tibble_class)
97-
x
97+
if (is.null(class)) {
98+
class <- tibble_class_no_data_frame
99+
} else {
100+
class <- c(class[!class %in% tibble_class], tibble_class_no_data_frame)
101+
}
102+
103+
slots <- c("x", "n", "class")
104+
args[slots] <- list(x, nrow, class)
105+
106+
# `new_data_frame()` restores compact row names
107+
args[["row.names"]] <- NULL
108+
109+
# do.call() is faster than exec() in this case
110+
do.call(new_data_frame, args)
98111
}
99112

100113
#' @description
@@ -148,6 +161,7 @@ validate_nrow <- function(names, lengths, nrow) {
148161
}
149162

150163
tibble_class <- c("tbl_df", "tbl", "data.frame")
164+
tibble_class_no_data_frame <- c("tbl_df", "tbl")
151165

152166
# Errors ------------------------------------------------------------------
153167

R/print.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#' the printed output can be customized in various ways.
2020
#' See `vignette("extending", package = "pillar")` for details.
2121
#'
22-
#' @inheritSection pillar::`pillar-package` Package options
22+
#' @inherit pillar::pillar_options
2323
#' @section Package options:
2424
#'
2525
#' The following options control printing of `tbl` and `tbl_df` objects:

R/tibble-package.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#' @importFrom vctrs unspecified vec_as_subscript2 num_as_location vec_ptype_abbr
1010
#' @importFrom vctrs vec_names vec_names2 vec_set_names
1111
#' @importFrom vctrs new_rcrd
12+
#' @importFrom vctrs new_data_frame
1213
#' @aliases NULL tibble-package
1314
#' @details
1415
#' `r lifecycle::badge("stable")`
@@ -35,7 +36,6 @@
3536
#' * Create a tibble: [tibble()], [as_tibble()], [tribble()], [enframe()]
3637
#' * Inspect a tibble: [print.tbl()], [glimpse()]
3738
#' * Details on the S3 `tbl_df` class: [`tbl_df-class`]
38-
#' @inheritSection formatting Package options
3939
#' @section Package options:
4040
#' The following option is used for viewing tabular data with `view()`:
4141
#' - `tibble.view_max`: Maximum number of rows shown if the input is not a

man/formatting.Rd

Lines changed: 52 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tibble-package.Rd

Lines changed: 0 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)