Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

col.names argument not used in write.csv.raw #26

Closed
andrewuhl opened this issue Jan 7, 2016 · 3 comments
Closed

col.names argument not used in write.csv.raw #26

andrewuhl opened this issue Jan 7, 2016 · 3 comments

Comments

@andrewuhl
Copy link

write.csv.raw = function(x, file = "", append = FALSE, sep = ",", nsep="\t",
                          col.names = TRUE, fileEncoding = "") {
  if (is.character(file)) {
    file <- if (nzchar(fileEncoding))
            file(file, ifelse(append, "ab", "wb"), encoding = fileEncoding)
        else file(file, ifelse(append, "ab", "wb"))
    on.exit(close(file))
  } else if (!isOpen(file, "w")) {
    open(file, "wb")
    on.exit(close(file))
  }

  r = as.output(x, sep = sep, nsep=nsep)
  writeBin(r, con=file)
}
@gregorybooma
Copy link

Looks like append and fileEncoding are also left out, though append seems to work. fileEncoding doesn't apply for me, but having col.names would be great. Currently doing the following as a workaround:

cat(noquote(paste0(paste0(names(df),collapse = ","),"\n")),file = "output.csv")
write.csv.raw(df,"output.csv",append=TRUE)

Note that "\n" is required to avoid starting the append on the first line of the file.

@demydd
Copy link

demydd commented Feb 18, 2016

It looks to work well.
At least in my case http://stackoverflow.com/questions/35295320/the-fastest-way-to-write-csv-file-by-write-csv-raw-iotools-package.
It would be nice to add ability to define decimal sign like ' dec="," ' .

@demydd
Copy link

demydd commented Feb 18, 2016

Comparison of 'write.csv.raw' and other write-methods (details see at http://stackoverflow.com/questions/35295320/the-fastest-way-to-write-csv-file-by-write-csv-raw-iotools-package):

system.time(write.csv.raw(n,"test.csv",sep=";",append=TRUE))
user system elapsed
15.61 1.17 21.92
system.time(write.table(n,"test.csv",sep=";",row.names=FALSE,dec=","))
user system elapsed
63.25 1.20 64.60
system.time(write.csv2(n,"test.csv",row.names=FALSE))
user system elapsed
63.71 1.28 65.38
system.time(write_csv(n, "test.csv", na = "NA"))
user system elapsed
136.75 3.60 141.24

statsmaths pushed a commit that referenced this issue Mar 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants