Re: [R] sink() output to another directory
On Fri, 14 Sep 2018, Ivan Krylov wrote: Just remove the slash from your print command (line 25 of rainfall-dubois-crk-all.r) because it's a syntax error (must be a typo). I.e. the above should be print(summary(estacada_wnw_wx)), not print(/summary(estacada_wnw_wx)) (do you notice the difference?). The rest of your sequence of commands is fine. Ivan, Yes, it was and I did not see it each time I looked at the code, ignoring the error message point me to it. I've now installed lintr and will use that on all my scripts before I run them. Regards, Rich __ R-help@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.
Re: [R] sink() output to another directory
В Thu, 13 Sep 2018 15:49:52 -0700 (PDT) Rich Shepard пишет: > sink('stat-summaries/estacada-wnw-precip.txt') > print(/summary(estacada_wnw_wx)) > sink() Just remove the slash from your print command (line 25 of rainfall-dubois-crk-all.r) because it's a syntax error (must be a typo). I.e. the above should be print(summary(estacada_wnw_wx)), not print(/summary(estacada_wnw_wx)) (do you notice the difference?). The rest of your sequence of commands is fine. -- Best regards, Ivan __ R-help@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.
Re: [R] sink() output to another directory [RESOLVED]
On Thu, 13 Sep 2018, Rich Shepard wrote: sink('stat-summary/example-output.txt') print(summary(df)) sink() My apologies to everyone for not seeing a typo further in the script. I had the path to the appropriate directory in the sink() function and the print() function had only the command as above. Except for one dataframe. In that one I had stuck a '/' in front of the summary() function and that caused the problem. I just found an R equivalent to lint to find such syntactical errors before I embarrass myself again. Has anyone used lintr from github? I will definitely start using this on my scripts. Mea culpa, Rich __ R-help@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.
Re: [R] sink() output to another directory
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 on behalf of Rich Shepard 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 __ R-help@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]] __ R-help@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.
Re: [R] sink() output to another directory
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 __ R-help@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.
Re: [R] sink() output to another directory
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 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@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]] __ R-help@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.
Re: [R] sink() output to another directory
On Thu, Sep 13, 2018 at 7:12 PM Rich Shepard wrote: > > On Thu, 13 Sep 2018, Henrik Bengtsson wrote: > > >> sink('stat-summaries/estacada-se-precip.txt') > >> print(summary(estacada_se_wx)) > >> sink() > >> > >> while accepting: > >> > >> pdf('../images/rainfall-estacada-se.pdf') > >> > >> plot(rain_est_se) > >> dev.off() > >> > >>Changing the sink() file to > >> './stat-summaries/estacada-se-precip.txt' > >> > >> generates the same error > > > > "same error" as what? (ambiguity is the reason for not being able to > > help you - all the replies in this thread this far are correct and on > > the spot) > > > > BTW, not that it should matter, what is your operating system and version > > of R? > > Henrik, > >As I wrote in earlier messages: > > sink('stat-summaries/estacada-wnw-precip.txt') > print(summary(estacada_se_wx)) > sink() > > results in > > 24: sink('stat-summaries/estacada-wnw-precip.txt') > 25: print(/ > ^ > Does not matter if I use single or double quotes. > >The message that print() doesn't like the forward slash results when I > specify 'stat-summaries/estacada-wnw-precip.txt' or > './stat-summaries/estacada-wnw-precip.txt'. Since it is impossible to get that error message (which is a syntax error, i.e. the R parser does not accept the code as written and it never gets to the point where the R engine even runs your code) for the code you are showing, I strongly suspect that you didn't source() the same file that you were editing (the one that contains the three-line code you are displaying above). I see from one of your later message that you've got it to work now. /Henrik > >Running R-3.5.1 on Slackware-14.2. > > Rich > > __ > R-help@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. __ R-help@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.
Re: [R] sink() output to another directory
It is not possible for the current working directory to begin with "../". That is like saying n=n-1, because once follow the two dots up to the next directory the two dots refer to the next directory up. I don't think anyone in this list understands what is going on for you, so I recommend using the reprex package to create a confirmed-reproducible example and send that along so we can identify the bug or user error that is puzzling you. On September 13, 2018 3:42:26 PM PDT, Henrik Bengtsson wrote: >On Thu, Sep 13, 2018 at 3:33 PM Rich Shepard >wrote: >> >>Neither ?sink nor ?capture.output indicates how the output file >can be >> specified to be in a directory other than the cwd. >> >>When the cwd is ../analyses/ and I want the output to be in >> ../analyses/stat-summaries/ how do I write this? >> >>sink('example-output.txt') >>print(summary(df)) >>sink() >> >> writes output to the current directory. My attempts to prefix the >file name >> with ./ or just / don't sit well with R. > >Hi welcome to R-help. Please help the helper(s) to help you by being >as explicit as possible what you've tried (i.e. cut'n'paste your >code), provide error messages (cut'n'paste) you get, if any, and/or >what you mean by "don't sit well with R" (that can mean many different >things). > >/Henrik > >> What is the proper syntax? >> >> TIA, >> >> Rich >> >> __ >> R-help@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. > >__ >R-help@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. -- Sent from my phone. Please excuse my brevity. __ R-help@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.
Re: [R] sink() output to another directory
On 09/14/2018 02:12 PM, Rich Shepard wrote: On Thu, 13 Sep 2018, Henrik Bengtsson wrote: sink('stat-summaries/estacada-se-precip.txt') print(summary(estacada_se_wx)) sink() while accepting: pdf('../images/rainfall-estacada-se.pdf') plot(rain_est_se) dev.off() Changing the sink() file to './stat-summaries/estacada-se-precip.txt' generates the same error "same error" as what? (ambiguity is the reason for not being able to help you - all the replies in this thread this far are correct and on the spot) BTW, not that it should matter, what is your operating system and version of R? Henrik, As I wrote in earlier messages: sink('stat-summaries/estacada-wnw-precip.txt') print(summary(estacada_se_wx)) sink() results in 24: sink('stat-summaries/estacada-wnw-precip.txt') 25: print(/ ^ Does not matter if I use single or double quotes. The message that print() doesn't like the forward slash results when I specify 'stat-summaries/estacada-wnw-precip.txt' or './stat-summaries/estacada-wnw-precip.txt'. Running R-3.5.1 on Slackware-14.2. This would appear to have nothing to do with sink(). There is something weird about your data set estacada_se_wx or the summary thereof that print() doesn't like. If I do: system("mkdir stat-summaries") estacada_se_wx <- rnorm(10) sink('stat-summaries/estacada-se-precip.txt') print(summary(estacada_se_wx)) sink() system("cat stat-summaries/estacada-se-precip.txt") I get: Min. 1st Qu. MedianMean 3rd Qu.Max. -1.7292 -0.7621 0.5428 0.2808 1.2603 1.7702 OMMM!!! cheers, Rolf Turner -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276 __ R-help@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.
Re: [R] sink() output to another directory
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 Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Thu, Sep 13, 2018 at 7:12 PM Rich Shepard wrote: > > On Thu, 13 Sep 2018, Henrik Bengtsson wrote: > > >> sink('stat-summaries/estacada-se-precip.txt') > >> print(summary(estacada_se_wx)) > >> sink() > >> > >> while accepting: > >> > >> pdf('../images/rainfall-estacada-se.pdf') > >> > >> plot(rain_est_se) > >> dev.off() > >> > >>Changing the sink() file to > >> './stat-summaries/estacada-se-precip.txt' > >> > >> generates the same error > > > > "same error" as what? (ambiguity is the reason for not being able to > > help you - all the replies in this thread this far are correct and on > > the spot) > > > > BTW, not that it should matter, what is your operating system and version > > of R? > > Henrik, > >As I wrote in earlier messages: > > sink('stat-summaries/estacada-wnw-precip.txt') > print(summary(estacada_se_wx)) > sink() > > results in > > 24: sink('stat-summaries/estacada-wnw-precip.txt') > 25: print(/ > ^ > Does not matter if I use single or double quotes. > >The message that print() doesn't like the forward slash results when I > specify 'stat-summaries/estacada-wnw-precip.txt' or > './stat-summaries/estacada-wnw-precip.txt'. > >Running R-3.5.1 on Slackware-14.2. > > Rich > > __ > R-help@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. __ R-help@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.
Re: [R] sink() output to another directory
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 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@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]] __ R-help@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.
Re: [R] sink() output to another directory
For the second time: Rich, there should be no slash in the print() command. Use the form sink("../directory/file") print(summary(foo)) ### no slashes here sink(NULL) Peter On Thu, Sep 13, 2018 at 7:12 PM Rich Shepard wrote: > On Thu, 13 Sep 2018, Henrik Bengtsson wrote: > > >> sink('stat-summaries/estacada-se-precip.txt') > >> print(summary(estacada_se_wx)) > >> sink() > >> > >> while accepting: > >> > >> pdf('../images/rainfall-estacada-se.pdf') > >> > >> plot(rain_est_se) > >> dev.off() > >> > >>Changing the sink() file to > >> './stat-summaries/estacada-se-precip.txt' > >> > >> generates the same error > > > > "same error" as what? (ambiguity is the reason for not being able to > > help you - all the replies in this thread this far are correct and on > > the spot) > > > > BTW, not that it should matter, what is your operating system and > version of R? > > Henrik, > >As I wrote in earlier messages: > > sink('stat-summaries/estacada-wnw-precip.txt') > print(summary(estacada_se_wx)) > sink() > > results in > > 24: sink('stat-summaries/estacada-wnw-precip.txt') > 25: print(/ > ^ > Does not matter if I use single or double quotes. > >The message that print() doesn't like the forward slash results when I > specify 'stat-summaries/estacada-wnw-precip.txt' or > './stat-summaries/estacada-wnw-precip.txt'. > >Running R-3.5.1 on Slackware-14.2. > > Rich > > __ > R-help@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]] __ R-help@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.
Re: [R] sink() output to another directory
On Thu, 13 Sep 2018, Henrik Bengtsson wrote: sink('stat-summaries/estacada-se-precip.txt') print(summary(estacada_se_wx)) sink() while accepting: pdf('../images/rainfall-estacada-se.pdf') plot(rain_est_se) dev.off() Changing the sink() file to './stat-summaries/estacada-se-precip.txt' generates the same error "same error" as what? (ambiguity is the reason for not being able to help you - all the replies in this thread this far are correct and on the spot) BTW, not that it should matter, what is your operating system and version of R? Henrik, As I wrote in earlier messages: sink('stat-summaries/estacada-wnw-precip.txt') print(summary(estacada_se_wx)) sink() results in 24: sink('stat-summaries/estacada-wnw-precip.txt') 25: print(/ ^ Does not matter if I use single or double quotes. The message that print() doesn't like the forward slash results when I specify 'stat-summaries/estacada-wnw-precip.txt' or './stat-summaries/estacada-wnw-precip.txt'. Running R-3.5.1 on Slackware-14.2. Rich __ R-help@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.
Re: [R] sink() output to another directory
On Thu, Sep 13, 2018 at 6:05 PM Rich Shepard wrote: > > On Thu, 13 Sep 2018, MacQueen, Don wrote: > > > In my experience, any path that can be used at the shell prompt in a > > unix-alike can be used anywhere that R wants a file name. > > Don, > >That's been my experiences, too. > > > Hopefully, that helps... > >That's why I don't understand why the plot() function accepts the > different directory while the sink() function (here) doesn't. > >I showed R rejecting: > > sink('stat-summaries/estacada-se-precip.txt') > print(summary(estacada_se_wx)) > sink() > > while accepting: > > pdf('../images/rainfall-estacada-se.pdf') > > plot(rain_est_se) > dev.off() > >Changing the sink() file to > './stat-summaries/estacada-se-precip.txt' > > generates the same error "same error" as what? (ambiguity is the reason for not being able to help you - all the replies in this thread this far are correct and on the spot) BTW, not that it should matter, what is your operating system and version of R? /Henrik > while I regularly use this syntax to copy files or > specify the relative path to an executable file. > > Regards, > > Rich > > __ > R-help@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. __ R-help@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.
Re: [R] sink() output to another directory
On Thu, 13 Sep 2018, MacQueen, Don wrote: In my experience, any path that can be used at the shell prompt in a unix-alike can be used anywhere that R wants a file name. Don, That's been my experiences, too. Hopefully, that helps... That's why I don't understand why the plot() function accepts the different directory while the sink() function (here) doesn't. I showed R rejecting: sink('stat-summaries/estacada-se-precip.txt') print(summary(estacada_se_wx)) sink() while accepting: pdf('../images/rainfall-estacada-se.pdf') plot(rain_est_se) dev.off() Changing the sink() file to './stat-summaries/estacada-se-precip.txt' generates the same error while I regularly use this syntax to copy files or specify the relative path to an executable file. Regards, Rich __ R-help@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.
Re: [R] sink() output to another directory
In my experience, any path that can be used at the shell prompt in a unix-alike can be used anywhere that R wants a file name. [that is, when running R on a unix-alike system, and when pwd at the shell prompt returns the same value as getwd() in R] Hopefully, that helps... -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 Lab cell 925-724-7509 On 9/13/18, 3:49 PM, "R-help on behalf of Rich Shepard" wrote: On Thu, 13 Sep 2018, Duncan Murdoch wrote: > What did you try? Prefixing with either ./ or / doesn't make any sense. Duncan, Using linux (and perhaps other unices) ./ and / refer to the current directory. My code, to print to the sub-directory (../analyses/stat-summaries/) when the script is being run in ../analyses: sink('stat-summaries/estacada-wnw-precip.txt') print(/summary(estacada_wnw_wx)) sink() Rich __ R-help@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. __ R-help@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.
Re: [R] sink() output to another directory
On Fri, 14 Sep 2018, Rolf Turner wrote: This is simply incorrect; "./" refers to the current directory but "/" refers to the root directory. Rolf, I was not sufficientl clear. Note that sink("./mung.txt") gives the same result as sink("mung.txt"). I.e. the "./" is redundant. If you have a directory "gorp" in your current directory, then sink("gorp/mung.txt") will put the sink() output into the file "mung.txt" in the directory "gorp". sink('stat-summaries/estacada-wnw-precip.txt') print(summary(estacada_se_wx)) sink() results in 24: sink('stat-summaries/estacada-wnw-precip.txt') 25: print(/ ^ Does not matter if I use single or double quotes. Regards, Rich __ R-help@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.
Re: [R] sink() output to another directory
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@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.
Re: [R] sink() output to another directory
On 09/14/2018 10:49 AM, Rich Shepard wrote: On Thu, 13 Sep 2018, Duncan Murdoch wrote: What did you try? Prefixing with either ./ or / doesn't make any sense. Duncan, Using linux (and perhaps other unices) ./ and / refer to the current directory. This is simply incorrect; "./" refers to the current directory but "/" refers to the root directory. Note that sink("./mung.txt") gives the same result as sink("mung.txt"). I.e. the "./" is redundant. If you have a directory "gorp" in your current directory, then sink("gorp/mung.txt") will put the sink() output into the file "mung.txt" in the directory "gorp". cheers, Rolf Turner -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276 __ R-help@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.
Re: [R] sink() output to another directory
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 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@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]] __ R-help@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.
Re: [R] sink() output to another directory
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@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.
Re: [R] sink() output to another directory
On Thu, 13 Sep 2018, Duncan Murdoch wrote: What did you try? Prefixing with either ./ or / doesn't make any sense. Duncan, Using linux (and perhaps other unices) ./ and / refer to the current directory. My code, to print to the sub-directory (../analyses/stat-summaries/) when the script is being run in ../analyses: sink('stat-summaries/estacada-wnw-precip.txt') print(/summary(estacada_wnw_wx)) sink() Rich __ R-help@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.
Re: [R] sink() output to another directory
On Thu, Sep 13, 2018 at 3:33 PM Rich Shepard wrote: > >Neither ?sink nor ?capture.output indicates how the output file can be > specified to be in a directory other than the cwd. > >When the cwd is ../analyses/ and I want the output to be in > ../analyses/stat-summaries/ how do I write this? > >sink('example-output.txt') >print(summary(df)) >sink() > > writes output to the current directory. My attempts to prefix the file name > with ./ or just / don't sit well with R. Hi welcome to R-help. Please help the helper(s) to help you by being as explicit as possible what you've tried (i.e. cut'n'paste your code), provide error messages (cut'n'paste) you get, if any, and/or what you mean by "don't sit well with R" (that can mean many different things). /Henrik > What is the proper syntax? > > TIA, > > Rich > > __ > R-help@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. __ R-help@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.