You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Need to implement $<-.tbl_df for clearer warning when trying a partial update of a missing column #199
The warning arises ultimately from the check_names_df function, which is called within the $.tbl_df function. From what I understand the $.tbl_df, $<-.data.frame functions are being called in that order for the last step in the above example.
My questions are:
Why is $<-.data.frame not being called directly since there is no $<-.tbl_df?
Whenever df$col2[df$col1 == 'something'] <- val style is used, a warning is produced now. Do you think this style should be discouraged, since the warning is basically indirectly asking people to not use style like this.
I think $<-.data.frame is called directly, and then calls $.tbl_df to get the current value (which it needs anyway to carry out the partial update).
I don't think tibbles should be supporting this syntax, because it's potentially dangerous -- too easy to misspell a column name and end up with a wrong result. Initializing with NA first, as in the StackOverflow answer, is the better way in my opinion.
If the aim of that warning is to suggest a safer and future proof alternative to tibble_df$age[tibble_df$name == "mary"] <- 47, then it would be great to change the warning message from Unknown column: 'age' to Uninitialized column: 'age'. See ?good_tibble_programming for further information.
I am all for more robust ways of coding, but the message as it is makes me think that tibble has an issue when adding new columns, rather than thinking that the code I have been writing and using for years may not be the recommended way of working with tibbles.
Thanks for your hard work on the package in any case
changed the title [-]Question regarding the Unknown column '***' warning [/-][+]Need to implement $<-.tbl_df for clearer warning when trying a partial update of a missing column[/+]on Dec 2, 2016
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.
Activity
krlmlr commentedon Dec 1, 2016
Thanks.
$<-.data.frameis called directly, and then calls$.tbl_dfto get the current value (which it needs anyway to carry out the partial update).NAfirst, as in the StackOverflow answer, is the better way in my opinion.zeehio commentedon Dec 1, 2016
If the aim of that warning is to suggest a safer and future proof alternative to
tibble_df$age[tibble_df$name == "mary"] <- 47, then it would be great to change the warning message fromUnknown column: 'age'toUninitialized column: 'age'. See ?good_tibble_programming for further information.I am all for more robust ways of coding, but the message as it is makes me think that tibble has an issue when adding new columns, rather than thinking that the code I have been writing and using for years may not be the recommended way of working with tibbles.
Thanks for your hard work on the package in any case
krlmlr commentedon Dec 2, 2016
Fair enough, let's implement
$<-.tbl_df.[-]Question regarding the Unknown column '***' warning [/-][+]Need to implement $<-.tbl_df for clearer warning when trying a partial update of a missing column[/+]detect and warn about partial initialization
Merge branch 'b-#199-partial-init'. Closes #199.
universal warning (#199)
Merge tag 'v1.2-15'
Merge tag 'v1.3.0'
github-actions commentedon Dec 14, 2020
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.