Skip to content

Need to implement $<-.tbl_df for clearer warning when trying a partial update of a missing column #199

Closed

Description

@sainathadapa

This question is related to this stackoverflow question: http://stackoverflow.com/questions/39041115/fixing-a-multiple-warning-unknown-column

The following code produces a warning: (from stackoverflow answer)

library(tibble)
tibble_df <- tibble(id = c(1:3), name = c("mary", "jill","steve"))
tibble_df$test <- 'aa'
tibble_df$age[tibble_df$name == "mary"] <- 47
> Warning message:
> Unknown column 'age'

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:

  1. Why is $<-.data.frame not being called directly since there is no $<-.tbl_df?
  2. 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.

Activity

  1. krlmlr commented on Dec 1, 2016

    @krlmlr
    Member

    Thanks.

    1. 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).
    2. 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.
  2. zeehio commented on Dec 1, 2016

    @zeehio

    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

  3. krlmlr commented on Dec 2, 2016

    @krlmlr
    Member

    Fair enough, let's implement $<-.tbl_df.

  4. 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
  5. added this to the 1.3.0 milestone on Jan 4, 2017
  6. added 2 commits that reference this issue on Jan 7, 2017
  7. added a commit that references this issue on Apr 1, 2017
  8. github-actions commented on Dec 14, 2020

    @github-actions
    Contributor

    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.

  9. locked and limited conversation to collaborators on Dec 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions