Marcus Kriele
2013-Mar-02 13:35 UTC
[R] How to start console output with a comment sign (as in knitr)
Dear all, knitr writes a comment sign in front of each line of console output. This extremely useful, especially for beginners who are starting to write scripts. One could just compose their script in the console (getting immediate output) and then copy the whole chunk into their .r-file. I have been able to configure the options such that the prompt and the continuing line labels are replaced by blanks. However, I do not know how to automatically comment out each line of output. Ideally, my console would behave exactly like knitr. At my work place I only have access to the R console that is included the standard download for windows. I cannot replace it by an editor that may have additional features. Would there be a way to achieve the knitr-look in the standard console? Many thanks, Marcus
Bert Gunter
2013-Mar-02 17:28 UTC
[R] How to start console output with a comment sign (as in knitr)
?options Change the "prompt" option: options(prompt = "# ") ## is I think what you want. -- Bert On Sat, Mar 2, 2013 at 5:35 AM, Marcus Kriele <mkriele at me.com> wrote:> Dear all, > knitr writes a comment sign in front of each line of console output. This extremely useful, especially for beginners who are starting to write scripts. One could just compose their script in the console (getting immediate output) and then copy the whole chunk into their .r-file. > I have been able to configure the options such that the prompt and the continuing line labels are replaced by blanks. However, I do not know how to automatically comment out each line of output. Ideally, my console would behave exactly like knitr. > > At my work place I only have access to the R console that is included the standard download for windows. I cannot replace it by an editor that may have additional features. > > Would there be a way to achieve the knitr-look in the standard console? > > Many thanks, Marcus > ______________________________________________ > R-help at r-project.org mailing list > 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.-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
Greg Snow
2013-Mar-02 18:06 UTC
[R] How to start console output with a comment sign (as in knitr)
Try the following to see if it does what you want: ## init con <- textConnection("output", "w") options(echo=FALSE) sink(con) addTaskCallback( function(expr, out, err, vis) { sink() close(con) if(vis) { cat(paste("#", output, collapse="\n"), "\n") } con <- textConnection("output", "w") sink(con) TRUE }) 3+4 5*6 tmp <- 7-8 ls() ### clean up when finished removeTaskCallback(1) sink() options(echo=TRUE) This misses errors and warnings, but should do what you want for everything else. On Sat, Mar 2, 2013 at 6:35 AM, Marcus Kriele <mkriele@me.com> wrote:> Dear all, > knitr writes a comment sign in front of each line of console output. This > extremely useful, especially for beginners who are starting to write > scripts. One could just compose their script in the console (getting > immediate output) and then copy the whole chunk into their .r-file. > I have been able to configure the options such that the prompt and the > continuing line labels are replaced by blanks. However, I do not know how > to automatically comment out each line of output. Ideally, my console > would behave exactly like knitr. > > At my work place I only have access to the R console that is included the > standard download for windows. I cannot replace it by an editor that may > have additional features. > > Would there be a way to achieve the knitr-look in the standard console? > > Many thanks, Marcus > ______________________________________________ > R-help@r-project.org mailing list > 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. >-- Gregory (Greg) L. Snow Ph.D. 538280@gmail.com [[alternative HTML version deleted]]