data_frame(x = 1, y = 2)
# Inputs are recycled using tidyverse recycling rules
data_frame(x = 1, y = 1:3)
# Strings are never converted to factors
class(data_frame(x = "foo")$x)
# List columns can be easily created
df <- data_frame(x = list(1:2, 2, 3:4), y = 3:1)
# However, the base print method is suboptimal for displaying them,
# so it is recommended to convert them to tibble
if (rlang::is_installed("tibble")) {
tibble::as_tibble(df)
}
# Named data frame inputs create data frame columns
df <- data_frame(x = data_frame(y = 1:2, z = "a"))
# The `x` column itself is another data frame
df$x
# Again, it is recommended to convert these to tibbles for a better
# print method
if (rlang::is_installed("tibble")) {
tibble::as_tibble(df)
}
# Unnamed data frame input is automatically unpacked
data_frame(x = 1, data_frame(y = 1:2, z = "a"))
Run the code above in your browser using DataLab