Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define responsibilities of new_tibble() #332

Merged
merged 11 commits into from
Nov 13, 2017
Merged

Conversation

krlmlr
Copy link
Member

@krlmlr krlmlr commented Nov 8, 2017

@hadley: What should new_tibble() check or enforce? We have as_tibble.list() that will check column names and recycle columns if necessary, but no attributes are copied. Should new_tibble() compute the row.names attribute if necessary and do additional checks?

Reference: #330 (comment)

@codecov
Copy link

codecov bot commented Nov 8, 2017

Codecov Report

Merging #332 into master will increase coverage by 0.17%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #332      +/-   ##
==========================================
+ Coverage    88.9%   89.08%   +0.17%     
==========================================
  Files          24       24              
  Lines        1109     1127      +18     
==========================================
+ Hits          986     1004      +18     
  Misses        123      123
Impacted Files Coverage Δ
R/tibble.R 98.14% <ø> (ø) ⬆️
R/as_tibble.R 100% <100%> (ø) ⬆️
R/utils.r 100% <100%> (ø) ⬆️
R/new.R 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update efe12f0...d865998. Read the comment docs.

@hadley
Copy link
Member

hadley commented Nov 8, 2017

I think it should at least require that x is a list and each element of x has the same length. I don't think it should copy attributes - that would feel more like a coercion function than an constructor.

@krlmlr krlmlr requested a review from hadley November 12, 2017 21:29
@krlmlr
Copy link
Member Author

krlmlr commented Nov 12, 2017

I was confused by your original comment in #211, agree that new_tibble() shouldn't support the ellipsis.

@krlmlr krlmlr force-pushed the f-new-tibble-responsibilities branch from e8be412 to 3b6aa24 Compare November 12, 2017 21:55
@krlmlr
Copy link
Member Author

krlmlr commented Nov 12, 2017

But then adv-r says there should be an ellipsis, thanks @DavisVaughan:

To allow subclasses, the parent constructor needs to have ... and subclass arguments:

Added it back, I think the code is a bit cleaner now.

@krlmlr krlmlr force-pushed the f-new-tibble-responsibilities branch from bb44ed6 to eb64ffa Compare November 12, 2017 23:55
R/new.R Outdated
#' @param subclass Subclasses to assign to the new object, default: none
#' @export
new_tibble <- function(x, ..., subclass = NULL) {
new_tibble <- function(x, ..., nrow = NULL, subclass = NULL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs a bit more documentation, i.e.:

  • x must be a named list (but names are not checked for correctness).
  • The rownames attribute is created automatically
  • The class is set to ...

R/new.R Outdated
x <- update_tibble_attrs(x, ...)
x <- set_tibble_class(x, subclass = subclass)
# Make sure that we override any row names that
# may have been there previously, in x or in ...
if (is.null(nrow)) nrow <- guess_nrow(x)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment doesn't seem right to me - I think it should just be "set row names" (in which case you can just remove it)

@krlmlr
Copy link
Member Author

krlmlr commented Nov 13, 2017

Do you want to take another look?

Copy link
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just a couple of minor quibbles.

R/new.R Outdated
new_tibble <- function(x, ..., subclass = NULL) {
#' @examples
#' new_tibble(list(a = 1:3, b = 4:6))
#' new_tibble(list(), nrow = 150, subclass = "my_tibble")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a little subtle without a comment

R/new.R Outdated
if (is.null(nrow)) nrow <- guess_nrow(x)
attr(x, "row.names") <- .set_row_names(nrow)

#' The `new_tibble()` constructor makes sure that the `row.names` attribute
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't this need @details?

@krlmlr krlmlr merged commit c7079fe into master Nov 13, 2017
@krlmlr krlmlr deleted the f-new-tibble-responsibilities branch November 13, 2017 16:39
krlmlr added a commit that referenced this pull request Nov 14, 2017
- Cleanly define responsibilities of `new_tibble()` (#332).
- Reexporting `has_name()` from rlang, instead of forwarding, to avoid warning when importing both rlang and tibble.
- Fix copying of attributes in `new_tibble()` (#330).
- Adapt vignette to new pillar methods.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants