Re: [R] sink() not working as expected [RESOLVED]

2021-11-03 Thread Rich Shepard
On Wed, 3 Nov 2021, Rui Barradas wrote: You do not assign the pipe output, so put the print statement as the last instruction of the pipe. The following works. # file: rhelp.R library(dplyr) mtcars %>% select(mpg, cyl, disp, hp, am) %>% mutate( sampdt = c("automatic", "manual")[am + 1L]

Re: [R] sink() not working as expected

2021-11-03 Thread Rui Barradas
Hello, You do not assign the pipe output, so put the print statement as the last instruction of the pipe. The following works. # file: rhelp.R library(dplyr) mtcars %>% select(mpg, cyl, disp, hp, am) %>% mutate( sampdt = c("automatic", "manual")[am + 1L] ) %>% print() Then, I've

Re: [R] sink() not working as expected

2021-11-03 Thread Rich Shepard
On Wed, 3 Nov 2021, Ivan Krylov wrote: instead. When you source() a script, auto-printing is not performed. This is explained in the first paragraph of ?source, but not ?sink. If you want to source() scripts and rely on their output (including sink()), you'll need to print() results explicitly.

Re: [R] sink() not working as expected

2021-11-02 Thread Andrew Simmons
cat in R behaves similarly to cat in unix-alikes, sends text to a stdout. Usually, that stdout would be a file, but usually in R it is the R Console. I think it might also help to note the difference between cat and print: x <- "test\n" cat(x) print(x) produces > cat(x) test > print(x) [1] "t

Re: [R] sink() not working as expected

2021-11-02 Thread Ivan Krylov
On Tue, 2 Nov 2021 10:18:07 -0700 (PDT) Rich Shepard wrote: > 'corvalis discharge summary\n' > summary(cor_disc) > sd(cor_disc$cfs) > '-\n' In the interactive mode, on the top level of execution, these commands behave as if you had written print(sink('data-summaries.txt')) print

Re: [R] sink() not working as expected

2021-11-02 Thread Rich Shepard
On Tue, 2 Nov 2021, Bert Gunter wrote: What do you think these 2 lines are doing? cat ('corvalis discharge summary\n') print(cat) Bert, If I used them in linux cat would display the file (as do more and less) and print() would be replaced with lpr Please consult ?cat . You might also spend

Re: [R] sink() not working as expected

2021-11-02 Thread Bert Gunter
What do you think these 2 lines are doing? cat ('corvalis discharge summary\n') print(cat) Please consult ?cat . You might also spend a bit of (more?) time with an R tutorial or two as you seem confused about how assignment (<-) works. Or maybe I'm confused about what is confusing you Bert G

Re: [R] sink() not working as expected

2021-11-02 Thread Rich Shepard
On Tue, 2 Nov 2021, Andrew Simmons wrote: You probably want to use cat and print for these lines. These things won't print when not run at the top level, so if you want them to print, you must specify that. Andrew, I modified the file to this: sink('data-summaries.txt') cat ('corvalis dischar

Re: [R] sink() not working as expected

2021-11-02 Thread Andrew Simmons
You probably want to use cat and print for these lines. These things won't print when not run at the top level, so if you want them to print, you must specify that. On Tue, Nov 2, 2021, 13:18 Rich Shepard wrote: > I've read ?sink and several web pages about it but it's not working > properly > w

[R] sink() not working as expected

2021-11-02 Thread Rich Shepard
I've read ?sink and several web pages about it but it's not working properly when I have the commands in a script and source() them. The file: library(tidyverse) library(lubridate) sink('data-summaries.txt') 'corvalis discharge summary\n' summary(cor_disc) sd(cor_disc$cfs) '-\n'