Skip to content
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

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

Closed
Breza opened this issue Dec 9, 2019 · 2 comments
Closed

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

Breza opened this issue Dec 9, 2019 · 2 comments
Milestone

Comments

@Breza
Copy link

Breza commented Dec 9, 2019

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().
@krlmlr krlmlr closed this as completed in 6a37ca8 Dec 19, 2019
@krlmlr
Copy link
Member

krlmlr commented Dec 19, 2019

Thanks for raising this. Turns out our as_tibble.NULL() method was responsible for this.

@krlmlr krlmlr added this to the 3.0.0 milestone Mar 21, 2020
@github-actions
Copy link
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.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants