Home > Blockchain >  Does R have a means of saving a Decimal for arrow into parquet files?
Does R have a means of saving a Decimal for arrow into parquet files?

Time:08-12

In python there's the decimal module whereby you can store decimal values without fear of falling into the floating point trap. Does R have a similar package?

In particular I'm looking for a way to save an R object to an arrow table/parquet file where one or more columns are Decimal type.

If I do

abc=data.table(a=c(1.23,2.34,3.45))
as_arrow_table(abc, schema=schema(field('a', decimal(3,2))))

I get Error: NotImplemented: Extend

CodePudding user response:

Because https://issues.apache.org/jira/browse/ARROW-11631 has not yet been done, you can't pass the schema in like that to the conversion function. But you can create the table and then cast it to decimal like this:

arrow_table(abc)$cast(schema(a = decimal(3, 2)))

# Table
# 3 rows x 1 columns
# $a <decimal128(3, 2)>
  • Related