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 . .
.)
sink(path)
print(. . . an R object . . .)
sink()
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
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
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)
________________________________
From: R-help <[email protected]> on behalf of Rich Shepard
<[email protected]>
Sent: Friday, September 14, 2018 8:38 AM
To: R-help
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 .
Bert,
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.
Regards,
Rich
______________________________________________
[email protected] 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.
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.