[Rd] sep hard coded in write.ftable

SOEIRO Thomas Thom@@@SOEIRO @end|ng |rom @p-hm@|r
Wed Sep 1 17:01:43 CEST 2021


Dear all,

(This is a follow up of a previous suggestion for ftable that was added in R 4.1.0: https://stat.ethz.ch/pipermail/r-devel/2020-May/079451.html)

The sep argument is hard coded in write.ftable:
	
write.ftable <- function(x, file = "", quote = TRUE, append = FALSE,
			 digits = getOption("digits"), ...)
{
    r <- format.ftable(x, quote = quote, digits = digits, ...)
    cat(t(r), file = file, append = append,
	sep = c(rep(" ", ncol(r) - 1), "\n"))
    invisible(x)
}

A minor change would allow users to modify it:

write.ftable2 <- function(x, file = "", quote = TRUE, append = FALSE,
                          digits = getOption("digits"), sep = " ", ...)
{
  r <- stats:::format.ftable(x, quote = quote, digits = digits, ...)
  cat(t(r), file = file, append = append,
      sep = c(rep(sep, ncol(r) - 1), "\n"))
  invisible(x)
}

This would allow to avoid a previous call to format.ftable (although write.ftable is significantly slower than write.table):

ftable(formula = wool + tension ~ breaks, data = warpbreaks) |>
  format(quote = FALSE) |>
  write.table(sep = ";", row.names = FALSE, col.names = FALSE)

ftable(formula = wool + tension ~ breaks, data = warpbreaks) |>
  write.ftable2(sep = ";")

Best regards,

Thomas



More information about the R-devel mailing list