From tim.triche at gmail.com  Tue Jul 19 16:44:33 2011
From: tim.triche at gmail.com (Tim Triche, Jr.)
Date: Tue, 19 Jul 2011 07:44:33 -0700
Subject: [Rd] hanging spaces prior to linebreak from cat()
Message-ID: <CAC+N9BVVhujS93qFqLAUiY_=gVRVTCeuDrb4jH2zju6K0hgC+Q@mail.gmail.com>

(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)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=C              LC_MESSAGES=C
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
 [1] EGC.tools_1.0
IlluminaHumanMethylation27k.db_1.4.6
 [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>


[Rd] hanging spaces prior to linebreak from cat()
Tim Triche, Jr.