Home > Blockchain >  R write.csv has weird formats in Notepad
R write.csv has weird formats in Notepad

Time:04-17

I’m doing a very simple write.csv() after manipulating strings and dates.

Everything looks good in the csv file but when I open in notepad the date format changes and there are quotes around everything.

Is there something I can do in R to prevent this?

CodePudding user response:

As a first step/guess without seeing the code I'd think it would be due to the type/class that R has assigned to the columns in your dataframe. Are they of type chr or int or other?

CodePudding user response:

First we need to see some of your code to actually figure out what the problem is and how to solve it.

Can you give us a reproducible example of the code you are using and the output you are getting?

As an aside, I would recommend the readr::write_csv function which has ~better~ options for output than the write.csv base R function in my humble opinion. In the documentation of this function, you can see that you can adjust when quotes are used in output.

readr::write_csv(
  x,
  file,
  na = "NA",
  append = FALSE,
  col_names = !append,
  quote = c("needed", "all", "none"),
  escape = c("double", "backslash", "none"),
  eol = "\n",
  num_threads = readr_threads(),
  progress = show_progress(),
  path = deprecated(),
  quote_escape = deprecated()
)
  • Related