如何在r中将list转换为schema?

n9vozmp4  于 2023-03-27  发布在  其他
关注(0)|答案(1)|浏览(105)

代码如下所示:

schema = schema(`Key`=int64(),
                 Sex = string(),
                `Age` = int64(),
                `Date of Birth` = date32(),
                `Institution` = string(),
                `Admission Date` = date32(),
                `Discharge Date` = date32(),
                `Elderly Home` = string(),
                `Paycode` = string())

class(schema)

R返回:

Error in `check_schema()`:
! `schema` must be an object of class 'Schema' not 'list'.
Run `rlang::last_error()` to see where the error occurred.

> class(schema)
[1] "list"

是否可以将列表转换为schema

我运行的版本:版本应为Arrow包版本:11.0.0.2.

> arrow::arrow_info()
Arrow package version: 11.0.0.2

Arrow options():
                       
arrow.use_threads FALSE
nbysray5

nbysray51#

我不能重现你描述的错误,但是我们可以通过使用rlang::inject()list对象转换为schema

library(arrow)

schema_ls <- list(
     `Key`=int64(),
     Sex = string(),
     `Age` = int64(),
     `Date of Birth` = date32(),
     `Institution` = string(),
     `Admission Date` = date32(),
     `Discharge Date` = date32(),
     `Elderly Home` = string(),
     `Paycode` = string())

rlang::inject(schema(!!!schema_ls))
#> Schema
#> Key: int64
#> Sex: string
#> Age: int64
#> Date of Birth: date32[day]
#> Institution: string
#> Admission Date: date32[day]
#> Discharge Date: date32[day]
#> Elderly Home: string
#> Paycode: string

关于OP中显示的错误,下面是我看到的:

library(arrow)

schema = schema(`Key`=int64(),
                Sex = string(),
                `Age` = int64(),
                `Date of Birth` = date32(),
                `Institution` = string(),
                `Admission Date` = date32(),
                `Discharge Date` = date32(),
                `Elderly Home` = string(),
                `Paycode` = string())
class(schema)
#> [1] "Schema"      "ArrowObject" "R6"

创建于2023-03-23带有reprex v2.0.2

相关问题