Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion r/src/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ arrow::Status AddMetadataFromDots(SEXP lst, int num_fields,
// "top level" attributes, only relevant if the first object is not named and a data
// frame
cpp11::strings names = Rf_getAttrib(lst, R_NamesSymbol);
if (names[0] == "" && Rf_inherits(VECTOR_ELT(lst, 0), "data.frame")) {
if (names[0] == "" && Rf_inherits(VECTOR_ELT(lst, 0), "data.frame") &&
Rf_xlength(lst) == 1) {
SEXP top_level = metadata[0] = arrow_attributes(VECTOR_ELT(lst, 0), true);
if (!Rf_isNull(top_level) && XLENGTH(top_level) > 0) {
has_top_level_metadata = true;
Expand Down
19 changes: 19 additions & 0 deletions r/tests/testthat/test-Table.R
Original file line number Diff line number Diff line change
Expand Up @@ -711,3 +711,22 @@ test_that("as_arrow_table() errors on data.frame with NULL names", {
names(df) <- NULL
expect_error(as_arrow_table(df), "Input data frame columns must be named")
})

test_that("we only preserve metadata of input to arrow_table when passed a single data.frame", {
# data.frame in, data.frame out
df <- data.frame(x = 1)
out1 <- as.data.frame(arrow_table(df))
expect_s3_class(out1, "data.frame", exact = TRUE)

# tibble in, tibble out
tib <- tibble::tibble(x = 1)
out2 <- as.data.frame(arrow_table(tib))
expect_s3_class(out2, c("tbl_df", "tbl", "data.frame"), exact = TRUE)

# GH-35038 - passing in multiple arguments doesn't affect return type
out3 <- as.data.frame(arrow_table(df, name = "1"))
out4 <- as.data.frame(arrow_table(name = "1", df))

expect_s3_class(out3, c("tbl_df", "tbl", "data.frame"), exact = TRUE)
expect_s3_class(out4, c("tbl_df", "tbl", "data.frame"), exact = TRUE)
})