Here's a hack to create an empty data frame with no rows and no columns:
iris[FALSE, FALSE]
#> data frame with 0 columns and 0 rows
Smarter-looking code creates a spurious column:
x <- list(NULL)
class(x) <- c("data.frame")
attr(x, "row.names") <- integer(0)
str(x)
#> 'data.frame': 0 obs. of 1 variable:
#> $ : NULL
Is there a non-hack alternative?
The reason to create such a thing is to satisfy a function that can handle empty data frames but not NULLs.
This is different from similar questions because it is about having no columns as well as no rows.