Rev 74821 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/write.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2018 R Core Team% Distributed under GPL 2 or later\name{write}\title{Write Data to a File}\usage{write(x, file = "data",ncolumns = if(is.character(x)) 1 else 5,append = FALSE, sep = " ")}\alias{write}\arguments{\item{x}{the data to be written out, usually an atomic vector.}\item{file}{a \code{\link{connection}}, or a character string namingthe file to write to. If \code{""}, print to the standard outputconnection.When \code{\link{.Platform}$OS.type != "windows"}, and itis \code{"|cmd"}, the output is piped to the command givenby \file{cmd}.}\item{ncolumns}{the number of columns to write the data in.}\item{append}{if \code{TRUE} the data \code{x} are appended to theconnection.}\item{sep}{a string used to separate columns. Using \code{sep = "\t"}gives tab delimited output; default is \code{" "}.}}\description{The data (usually a matrix) \code{x} are written to file \code{file}.If \code{x} is a two-dimensional matrix you need to transpose it to get thecolumns in \code{file} the same as those in the internal representation.}\references{Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)\emph{The New S Language}.Wadsworth & Brooks/Cole.}\seealso{\code{write} is a wrapper for \code{\link{cat}}, which gives furtherdetails on the format used.\code{\link{save}} for writing any \R objects,\code{\link{write.table}} for data frames,and \code{\link{scan}} for reading data.}\examples{# create a 2 by 5 matrixx <- matrix(1:10, ncol = 5)fil <- tempfile("data")# the file data contains x, two rows, five cols# 1 3 5 7 9 will form the first rowwrite(t(x), fil)if(interactive()) file.show(fil)unlink(fil) # tidy up# Writing to the "console" 'tab-delimited'# two rows, five cols but the first row is 1 2 3 4 5write(x, "", sep = "\t")}\keyword{file}\keyword{connection}