Skip to content

add_column() and add_row() should throw errors if the input is not a data frame #575

@DavisVaughan

Description

@DavisVaughan
tibble::add_column(as.matrix(mtcars), x = 1)
#> [[1]]
#> [1] 21
#> 
#> [[2]]
#> [1] 21
#> 
#> [[3]]
#> [1] 22.8
#> 
#> [[4]]
#> [1] 21.4
#> 
#> [[5]]
#> [1] 18.7
#> 
#> [[6]]
#> [1] 18.1
#> 
#> [[7]]
#> [1] 14.3
#> 
#> [[8]]
#> [1] 24.4
#> 
#> [[9]]
#> [1] 22.8
#> 
#> [[10]]
#> [1] 19.2
#> 
#> [[11]]
#> [1] 17.8
#> 
#> [[12]]
#>  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

tibble::add_row(as.matrix(mtcars), mpg = 4)
#> Error: New rows in `add_row()` must use columns that already exist:
#> * Can't find column `mpg` in `.data`.
#> Backtrace:
#>     █
#>  1. └─tibble::add_row(as.matrix(mtcars), mpg = 4)

add_row() throws an error, but it might be worth it to make it consistent with one that would be thrown with add_column(). I imagine just checking if .data is a data.frame and throwing an error otherwise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions