-
Notifications
You must be signed in to change notification settings - Fork 129
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
I think it should at least require that |
I was confused by your original comment in #211, agree that |
e8be412
to
3b6aa24
Compare
But then adv-r says there should be an ellipsis, thanks @DavisVaughan:
Added it back, I think the code is a bit cleaner now. |
bb44ed6
to
eb64ffa
Compare
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) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
Do you want to take another look? |
There was a problem hiding this 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") |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
?
@hadley: What should
new_tibble()
check or enforce? We haveas_tibble.list()
that will check column names and recycle columns if necessary, but no attributes are copied. Shouldnew_tibble()
compute therow.names
attribute if necessary and do additional checks?Reference: #330 (comment)