You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R语言中如何将列表转为Schema对象?Arrow包11.0.0.2报错求助

解决Arrow包中列表转Schema对象的问题

在Arrow 11.0.0.2版本中,确实可以将你生成的列表转换为Schema对象,有两种可行方式:

方式一:直接创建Schema对象(推荐)

不用先生成列表,直接用Schema$create()方法定义Schema,能直接得到Schema类对象:

schema <- Schema$create(
  `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"

方式二:将已有的列表转换为Schema对象

如果已经得到了那个列表,用as_schema()函数或者Schema$create()传入列表即可完成转换:

# 假设你已经有了这个列表
schema_list <- list(
  `Key`=int64(),
  Sex = string(),
  `Age` = int64(),
  `Date of Birth` = date32(),
  `Institution` = string(),
  `Admission Date` = date32(),
  `Discharge Date` = date32(),
  `Elderly Home` = string(),
  `Paycode` = string()
)

# 方法1:用as_schema转换
schema <- as_schema(schema_list)

# 方法2:用Schema$create传入列表
schema <- Schema$create(schema_list)

class(schema)
# 输出:[1] "Schema"

你之前用schema(...)得到列表,是因为该版本中这个调用方式返回的是字段列表而非Schema实例,改用上面的方法就能解决报错问题。

内容的提问来源于stack exchange,提问作者doraemon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 09:47:20