Remove the / from the print command, it does not belong there. sink("../directory/file.txt"); print(summary(foo)) sink(NULL) On Thu, Sep 13, 2018 at 4:03 PM Rich Shepard <rshepard at appl-ecosys.com> wrote:> On Thu, 13 Sep 2018, Rich Shepard wrote: > > > sink('example-output.txt') > > print(summary(df)) > > sink() > > Let me expand on this. When the script contains > > # Open PDF device to save plot > pdf('../images/rainfall-estacada-se.pdf') > ... > plot(rain_est_se) > dev.off() > > the file, rainfall-estacada-se.pdf is placed in the images directory, which > is on the same directory level as the one in which the script is being run. > I thought the equivalent syntax with sink() would work, but the print > command rejects the forward slash that plot() accepts: > > Error in source("rainfall-dubois-crk-all.r") : > rainfall-dubois-crk-all.r:25:7: unexpected '/' > > Is this more clear? > > Thanks, > > Rich > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
On Thu, 13 Sep 2018, Peter Langfelder wrote:> Remove the / from the print command, it does not belong there.Peter, So the print() function cannot accept a relative path to a different directory for its output? This does seem to be the case: source('rainfall-dubois-crk-all.r') Error in source("rainfall-dubois-crk-all.r") : rainfall-dubois-crk-all.r:25:7: unexpected '/' 24: sink('stat-summaries/estacada-wnw-precip.txt') 25: print(/ ^ Then I'll print to the cwd and move the files manually afterwards. Thanks, Rich
There is no path in print. The path (file) is set in sink(). Peter On Thu, Sep 13, 2018 at 4:35 PM Rich Shepard <rshepard at appl-ecosys.com> wrote:> On Thu, 13 Sep 2018, Peter Langfelder wrote: > > > Remove the / from the print command, it does not belong there. > > Peter, > > So the print() function cannot accept a relative path to a different > directory for its output? This does seem to be the case: > > source('rainfall-dubois-crk-all.r') > Error in source("rainfall-dubois-crk-all.r") : > rainfall-dubois-crk-all.r:25:7: unexpected '/' > 24: sink('stat-summaries/estacada-wnw-precip.txt') > 25: print(/ > ^ > > Then I'll print to the cwd and move the files manually afterwards. > > Thanks, > > Rich > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
Apologies if my advice wasn't clear: the file you want to write to goes in the sink() function/command. You can put the file anywhere on your file system, no need to write into current directory and then move the file. The print command is completely unaware of the file you point to in sink(). Technically, print() sends output to a device called "standard output" which is usually screen, but it can be changed to a file (_any_ writable file) using the sink() command. Hope this helps, Peter On Thu, Sep 13, 2018 at 4:35 PM Rich Shepard <rshepard at appl-ecosys.com> wrote:> On Thu, 13 Sep 2018, Peter Langfelder wrote: > > > Remove the / from the print command, it does not belong there. > > Peter, > > So the print() function cannot accept a relative path to a different > directory for its output? This does seem to be the case: > > source('rainfall-dubois-crk-all.r') > Error in source("rainfall-dubois-crk-all.r") : > rainfall-dubois-crk-all.r:25:7: unexpected '/' > 24: sink('stat-summaries/estacada-wnw-precip.txt') > 25: print(/ > ^ > > Then I'll print to the cwd and move the files manually afterwards. > > Thanks, > > Rich > > ______________________________________________ > 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. >[[alternative HTML version deleted]]