Skip to content

Calling as_tibble() without any argument creates empty tibble #683

@Breza

Description

@Breza

When you call as_tibble() without any arguments, it creates an empty tibble. This is a desired behavior for tibble() but I can't imagine a scenario when someone intentionally wants to create an empty tibble using as_tibble().

as_tibble()
# A tibble: 0 x 0

The analogous function from base R is as.data.frame(), which throws an error when called without parameters.

as.data.frame()
#Error in as.data.frame() : argument "x" is missing, with no default

This isn't really a bug since the problem results from a mistake in writing code. I noticed it when I forgot to add a pipe in a chain of operations. Below is a convoluted example. You shouldn't necessarily try to protect us from ourselves. But I figured it was still worth documenting.

mtcars %>% 
  select(mpg, hp, wt)
  as_tibble() -> mt_tibble

You might consider adding a warning.

as_tibble()
# Warning: as_tibble() called without any arguments. Empty tibble returned. To avoid this warning, call tibble() instead of as_tibble().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions