Skip to content

fwrite ignores options(scipen = 999) #2020

Description

@florianWickler

Hey,

I use options(scipen = 999) to avoid scientific notation. write.table() uses this option, but not fwrite() (data.table 1.10.0).

Example:

options(scipen = 999)
library(data.table)
dt <- data.table(a = 0.0001, b = 10^6)
write.table(dt, file = "wt.csv", row.names = FALSE)
fwrite(dt, file = "fw.csv")

Activity

  1. apprent commented on Jul 19, 2017

    @apprent
    library(data.table)
    
    aaa <- data.table(c(10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 
                        1e11, 1e12, 1e13, 1e14, 1e15, 1e16))
    
    options(scipen = 0)
    write.csv(aaa, "scipen-0-writecsv.txt")
    fwrite(aaa, "scipen-0-fwrite.txt")
    
    
    options(scipen = 3)
    write.csv(aaa, "scipen-3-writecsv.txt")
    fwrite(aaa, "scipen-3-fwrite.txt")
    
    
    options(scipen = 5)
    write.csv(aaa, "scipen-5-writecsv.txt")
    fwrite(aaa, "scipen-5-fwrite.txt")
    
    
    options(scipen = 10)
    write.csv(aaa, "scipen-10-writecsv.txt")
    fwrite(aaa, "scipen-10-fwrite.txt")
    
    
    options(scipen = 99)
    write.csv(aaa, "scipen-99-writecsv.txt")
    fwrite(aaa, "scipen-99-fwrite.txt")
    
  2. ajnisbet commented on Feb 22, 2018

    @ajnisbet

    Looks like this is hardcoded in fwrite.c?

    One workaround is to cast integer columns with bit64::as.integer64.

  3. unpinned this issue on Dec 22, 2018
  4. mattdowle commented on Jan 15, 2019

    @mattdowle
    Member

    And fwrite() tests in test.data.table() are affected by user setting options(scipen=) reported here with screenshots : https://twitter.com/ilarischeinin/status/1085082345013739520

  5. added this to the 1.12.4 milestone on Jan 30, 2019
  6. changed the title [-]fwrite ignors options(scipen = 999)[/-] [+]fwrite ignores options(scipen = 999)[/+] on Apr 9, 2019
  7. sjain777 commented on Apr 15, 2019

    @sjain777

    Turning off scientific notation in fwrite not working is an issue. Any attempt to reformat the data using standard R functions add slowness to a big-data use-case. Hence, getting this addressed in 1.12.4 as indicated above would be awesome, thanks much!

  8. MichaelChirico commented on Jul 21, 2019

    @MichaelChirico
    Member

    I have a basic working version up in fwrite_scipen branch, see #3716. Raising here since there are so many interested parties on this one...

    Also adding those who reacted since I'm not sure you'll be subscribed to notifications:

    @charles-plessy @mike-wise @ndukler @AndroidOatmeal @AlexIzydorczyk @novakowd @gamestrRUS @simkoum @jon-nagra @apprent @tony-stone @SimonPBiggs @AdamSpannbauer @everron @juliebehr @mt1022 @AndrewsOR @jrhawley @OrdiNeu @joblolabinette @grighi @TalSa @jeparsons @mgahan @ajnisbet @LannyFox @johndrummond @RoyalTS @acronymhaterheidi @PoGibas @malcook @yilun11 @dzeltzer @logworthy @yaakovfeldman @mattmotoki @bendae19 @dbradnum @ejoranlienea @Cruiseee @gorcha @diegogruber @rikutakei @r2evans @PoisonAlien

    Details

    code to get these since it was truncated above:

    library(gh)
    library(magrittr)
    # reactions API is "in development" so requires special header:
    react_header = 'application/vnd.github.squirrel-girl-preview+json'
    reaction_url = "/repos/Rdatatable/data.table/issues/2020/reactions?per_page=100"
    reaction_url %>% gh(.send_headers = c(Accept=react_header)) %>%
      sapply(`[[`, c('user', 'login')) %>% unique %>% paste0('@', . ) %>% 
      paste(collapse = ' ') %>% cat
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions