[Rd] hanging spaces prior to linebreak from cat()

From: Tim Triche, Jr. <tim.triche_at_gmail.com>
Date: Tue, 19 Jul 2011 07:44:33 -0700

(re-sending after confirming list subscription; apologies if this ends up being sent to the list twice)

Is the expected behavior from cat(), as used below, a hanging space before \n at the end of the emitted line?

 firstheader = gsub("\\s+$", "", paste(c("Hybridization REF", s, s), collapse = "\t"))
 cat(firstheader, "\n", file = filename)

When I run the above code, which is followed by appending the contents of a data.frame via write.table(), what I get is a file whose first line ends in a " \n" (note the space preceding the newline). I would think that the gsub() would have trimmed off this hanging space, but it doesn't. Is this a strange bug or expected behavior? I have attached the version of cat.R in from the SVN checkout I am running as my R build; it doesn't seem awry... ?!?

> sessionInfo()
R version 2.14.0 Under development (unstable) (2011-04-21 r55577) Platform: x86_64-unknown-linux-gnu (64-bit)


attached base packages:
[1] stats graphics grDevices datasets utils methods base

other attached packages:
[1] EGC.tools_1.0

[3] IlluminaHumanMethylation450k.db_1.4.6 org.Hs.eg.db_2.5.0
[5] RSQLite_0.9-4 DBI_0.2-5
[7] AnnotationDbi_1.15.7 Biobase_2.13.2

[9] gtools_2.6.2 reshape_0.8.4
[11] plyr_1.4

loaded via a namespace (and not attached): [1] annotate_1.31.0 grid_2.14.0 lattice_0.19-17 matrixStats_0.2.2 [5] methylumi_1.9.5 xtable_1.5-6

If people do not believe that mathematics is simple, it is only because they
do not realize how complicated life is.
John von Neumann<http://www-groups.dcs.st-and.ac.uk/~history/Biographies/Von_Neumann.html>

______________________________________________ R-devel_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel

Received on Tue 19 Jul 2011 - 21:55:56 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 20 Jul 2011 - 07:30:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive