Skip to content

Loss of precision in decimal places in write_csv2 #1087

@fjuniorr

Description

@fjuniorr

write_csv2 and write_excel_csv2 don't preserve the precision of decimal numbers in exported csv files, regardless of the current value of the getOption("digits"), as opposed to write_csv and write_excel_csv.

Since this is happening because of the transformation performed by change_decimal_separator, I hope this counts as a reproducible example:

digits <- getOption("digits")

df <- data.frame(value = 1234567.1)

options(digits = 7)
readr:::change_decimal_separator(df)
#>     value
#> 1 1234567

options(digits = 8)
readr:::change_decimal_separator(df)
#>       value
#> 1 1234567,1

options(digits = digits)

For reference, both utils::write.csv2 and data.table::fwrite with arguments dec = "," and sep = ";" also preserve the decimal numbers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions