Martin Batholdy
2013-Nov-16 19:20 UTC
[R] export vector with write() introduces line breaks
Hi, I have a long vector which I want to export as a simple ascii text file via write(1:600, file='test.txt', sep=',') When I open the text file with my text editor I see that the data is structured in columns. So it seems that line breaks are introduced. How can I prevent this? Thank you!
1. Read ?write carefully. Note what it says about write() writing to columns and the link to cat(). 2. Use cat() with appropriate arguments to write your file instead. e.g. cat(1:600, file=yourfile,fill=FALSE) Cheers, Bert On Sat, Nov 16, 2013 at 11:20 AM, Martin Batholdy <batholdy at googlemail.com> wrote:> Hi, > > I have a long vector which I want to export as a simple ascii text file via > write(1:600, file='test.txt', sep=',') > > When I open the text file with my text editor I see that the data is structured in columns. > So it seems that line breaks are introduced. > > How can I prevent this? > > > Thank you! > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374
Hi, I would like to set plot-options via par() and keep them for all plots that are created thereafter. Currently after each plot device the parameters I can set with par() are reseted to their default value, at least on a Mac (R 3.2.1). Is there a way to define the parameters for plotting once at the beginning and then keep them for an entire R session? Thank you!
Martin: One simple approach: write your own graphics functions that are simple wrappers to the plot functions you use that set the par() values as you wish. You could even put them in a package that is loaded at startup. See ?Startup My understanding is that so long as a graphics device remains open, new plots on it will reuse the same par() settings. See,e.g. ?plot.new. Cheers, Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Tue, Jun 23, 2015 at 8:54 AM, Martin Batholdy via R-help <r-help at r-project.org> wrote:> Hi, > > I would like to set plot-options via par() and keep them for all plots that are created thereafter. > Currently after each plot device the parameters I can set with par() are reseted to their default value, at least on a Mac (R 3.2.1). > > Is there a way to define the parameters for plotting once at the beginning and then keep them for an entire R session? > > > Thank you! > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
The Details section of ?par starts of with: "Each device has its own set of graphical parameters." (So this is not Mac-specific.) Strictly speaking, the options you set with par() are not "reset" when you open a new graphics device. Rather, when a new device is opened, it is initialized with default values of graphics parameters. If you can find where those default values are stored (in a brief search I did not find them), then perhaps you can change them at session startup time. I haven't tested this, but you might be able to make things a little more convenient by defining a function mypar <- function() par( {set whatever values you want} ) Then whenever you open a new device, immediately call that function: pdf() mypar() plot(x,y) dev.off() png() mypar() plot(x,y) dev.of() And so on. -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 6/23/15, 8:54 AM, "R-help on behalf of Martin Batholdy via R-help" <r-help-bounces at r-project.org on behalf of r-help at r-project.org> wrote:>Hi, > >I would like to set plot-options via par() and keep them for all plots >that are created thereafter. >Currently after each plot device the parameters I can set with par() are >reseted to their default value, at least on a Mac (R 3.2.1). > >Is there a way to define the parameters for plotting once at the >beginning and then keep them for an entire R session? > > >Thank you! > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.