跳到內容

建立 schema 或從物件中提取 schema。

用法

schema(...)

參數

...

fields、欄位名稱/data type 配對(或列表),或从中提取 schema 的物件

另請參閱

Schema,用於 Schema R6 物件的詳細文件

範例

# Create schema using pairs of field names and data types
schema(a = int32(), b = float64())
#> Schema
#> a: int32
#> b: double

# Create a schema using a list of pairs of field names and data types
schema(list(a = int8(), b = string()))
#> Schema
#> a: int8
#> b: string

# Create schema using fields
schema(
  field("b", double()),
  field("c", bool(), nullable = FALSE),
  field("d", string())
)
#> Schema
#> b: double
#> c: bool not null
#> d: string

# Extract schemas from objects
df <- data.frame(col1 = 2:4, col2 = c(0.1, 0.3, 0.5))
tab1 <- arrow_table(df)
schema(tab1)
#> Schema
#> col1: int32
#> col2: double
#> 
#> See $metadata for additional Schema metadata
tab2 <- arrow_table(df, schema = schema(col1 = int8(), col2 = float32()))
schema(tab2)
#> Schema
#> col1: int8
#> col2: float
#> 
#> See $metadata for additional Schema metadata