[R] sink() output to another directory
j@ork|n @end|ng |rom @om@um@ry|@nd@edu
Fri Sep 14 16:01:24 CEST 2018
As has been pointed out, the correct way to direct printing to a given location is using sink( . . . put path here . . . ) then print() and then sink() without any argument to turn off print direction. A helpful addition to this strategy is to use the file.path function to define a variable that specifies the path, i.e.
path <- file.path( . . . specify path here, see documentation of file.path . . .)
print(. . . an R object . . .)
The nice feature about using file.path is that it by default it formats the path correctly for the OS on which you are running R; paths are specified differently (i.e. use of slashes vs. back slashes) when using Linux vs. windows systems. Note that when specifying the path using file.path rather than having to format the path according to the dictates of your OS, all you need to do is to specify the elements of the path
path <- file.path("data",''FIPSstudy","exercisetests"). The result will be a character string that is formatted properly for your OS.
John David Sorkin M.D., Ph.D.
Professor of Medicine
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
Baltimore VA Medical Center
10 North Greene Street
Baltimore, MD 21201-1524
(Fax) 410-605-7913 (Please call phone number above prior to faxing)
From: R-help <r-help-bounces using r-project.org> on behalf of Rich Shepard <rshepard using appl-ecosys.com>
Sent: Friday, September 14, 2018 8:38 AM
Subject: Re: [R] sink() output to another directory
CAUTION: This message originated from a non UMB, UMSOM, FPI, or UMMS email system. Whether the sender is known or not known, hover over any links before clicking and use caution opening attachments.
On Thu, 13 Sep 2018, Bert Gunter wrote:
> I find your "explanation" confusing. You appear to be misusing print().
> Please read ?print carefully. You print objects in R, not files. Objects
> in R do not have "/" in their names (without some trickery). See
> ?make.names .
I had read both ?print and ?print.default looking for information about
placing the printed object in another directory, and found nothing.
My initial assumption was that print() worked similar to plot(). I use
plot() after specifying a pdf file as output and thought that sink() (which
?sink tells me diverts R output to a connection (and stops it as dev.off
stops writing to the pdf file). That sink() apparently does not work the
same way is why I posted my question.
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help