How to get fwrite() not to double quotes?

前端 未结 1 1532
你的背包
你的背包 2021-01-16 09:39

I read a csv file containing html code in its fields using fread, do some maintenance on it and write the resulting datatable to a file using fwrite

相关标签:
1条回答
  • 2021-01-16 10:40

    Two possible solutions (using v1.10.0 of data.table):

    1: Use the quote = FALSE parameter:

    fwrite(dt, 'fwrite.csv', quote = FALSE)
    

    When opening the file in a text editor, you will see this:

    htmlcode
    <colspan="7">
    <colspan="8">
    

    2: Replace the double brackets with single one (as also suggeted by @joel.wilson in the comments):

    dt[, htmlcode := gsub('\"', '\'', htmlcode)]
    fwrite(dt, 'fwrite.csv')
    

    When opening the file in a text editor, you will see this:

    htmlcode
    <colspan='7'>
    <colspan='8'>
    
    0 讨论(0)
提交回复
热议问题