How to suppress output in RStudio? - r

I need to suppress my output when I run my R scripts in RStudio. There are a lot of comments in my scripts, and the comments are printed when I run the file.
I realize that others have asked how to do this from the command prompt - How to suppress output. I'm not interested in that.
I just want to know how to suppress the output in RStudio. The only exception to this should be print statements. Thanks in advance.

Use source instead of source with echo in R Studio.
Same in MAC.

Ctrl+Shift+S will do the trick. In mac, it will be Shift+Command+S.

Related

Run Rmarkdown.rmd outside R editor

I am still pretty new to R, but couldn't seem to find solution to my question.
It's quite simple:
I have a .rmd file written and ready to run, but instead of openning it from R or Rstudio, Is there a way I can knit it automatically without opening that file?
Please kindly guide me how should I do this, screenshot would be much appreciated!!
Thanks in advance!!
Added: So I took nrussell's advice and tried run that on my windows command line, but I am seeing "The filename, directory name, or volumn label syntax is incorrect". Thoughts? Thank you all for your comments!
did a cd RMD's path , then used #nrussell's code. and it worked.
Somehow, I couldn't use specified RMD file path such as C:\XXX\XXXX.rmd, but if I cd to there first, it worked.

R Run knitr from a batch-file (windows)

I run some automatic reports each day with batch-files on my windows-computer. But how do I do this with a .rmd file and generate the html-output?
So, this works for me using a batchfile with a normal .R file:
"C:\R\R-3.0.1\bin\x64\Rscript.exe" --default-packages=methods
"C:\R\R-3.0.1\bin\x64\Scripts\models.R"
But, this won't:
"C:\R\R-3.0.1\bin\x64\Rscript.exe" --default-packages=methods,knitr
"C:\R\R-3.0.1\bin\x64\Scripts\test_knitr.Rmd"
I've tried some variations inspired by command-line like:
"C:\R\R-3.0.1\bin\x64\Rscript.exe" --default-packages=methods,knitr
knit("C:\R\R-3.0.1\bin\x64\Scripts\test_knitr.Rmd")
But no succes so far! Im a total knitr/.rmd newbee, so I'm not even sure it can be done.
I use something along the lines
Rscript -e "require ('knitr'); knit ('test.Rmd')"
I use
"C:\Program Files\R\R-3.5.1\bin\Rscript.exe" -e "library('knitr'); knit('C:/Users/test_doc.Rmd')"
pause
Like "cbeleites supports Monica" said using the full path.
Don't forget that in R we must use "/" and not "\" like in Windows.
So in the R call we use "\" because we are talking to Windows
and in the knit we use "/" because we are talking to R.
I hope it help.

Is there any way in Linux to show what's going on about the freezing code on the R session?

I am running a set of selected code on R. Like
source("/tmp/r-plugin-honli/Rsource-2704-quantmod.R")
There is no output. Only the prompt '>' flickered there.
I use 'killall' to kill the R session. But I don't know where is wrong on the code. Because R did not give any output. How could I know what's going on about the code.
I'd try two things:
Run the code interactively. As in, open the Rsource-2704 file and run its lines one by one.
If that doesn't replicate the problem or is not possible, you can take Joshua Ulrich's suggestion or use:
R CMD BATCH --vanilla Rsource-2704-quantmod.R out.log
Which will run the code in a batch mode and output the usual console lines to a file called out.log (you can name it whatever you like).
Instead of using print statements, you could also take a look at the browser() command. This drops you into an interactive session at the point where the command is put. This works particularly well when trying to figure out what is happening inside a function, although I don't know if your script contains them.

Sweave syntax highlighting in output

Has anyone managed to get color syntax-highlighting working in the output of Sweave documents? I've been able to customize the output style by adding boxes, etc. in the Sweave.sty file as follows:
\DefineVerbatimEnvironment{Sinput}{Verbatim}{fontseries=bc,frame=single}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{frame=leftline}
\DefineVerbatimEnvironment{Scode}{Verbatim}{fontseries=bc}
And I can get the minted package to do syntax highlighting of verbatim-code blocks in my document like so:
\begin{minted}{perl}
use Foo::Bar;
...
\end{minted}
but I'm not sure how to combine the two for R input sections. I tried the following:
\DefineVerbatimEnvironment{Sinput}{minted}{r}
\DefineVerbatimEnvironment{Scode}{minted}{r}
Any suggestions?
Yes, look at some of the vignettes for Rcpp as for example (to pick just one) the Rcpp-FAQ pdf.
We use the highlight by Romain which itself can farm out to the hightlight binary by Andre Simon. It makes everything a little more involved---Makefiles for the vignettes etc pp---but we get colourful output from R and C/C++ code. Which makes it worth it.
I have a solution that has worked for me, I have not tried it on any other systems though so things may not work out of the box for you. I've posted some code at https://gist.github.com/797478 that is a set of modified Rweave driver functions that make use of minted blocks instead of verbatim blocks.
To use this driver just specify it when calling the Sweave function with the driver=RweaveLatexMinted() option.
Here's how I've ended up solving it, starting from #daroczig's suggestion.
\usepackage{minted}
\renewenvironment{Sinput}{\minted[frame=single]{r}}{\endminted}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{frame=leftline}
\DefineVerbatimEnvironment{Scode}{Verbatim}{}
While I was at it, I needed to get caching working because I'm using large data sets and one chunk was taking around 3 minutes to complete. So I wrote this zsh shell function to process an .Rnw file with caching:
function sweaveCache() {
Rscript -e "library(cacheSweave); setCacheDir(getwd()); Sweave('$1.Rnw', driver = cacheSweaveDriver)" &&
pdflatex --shell-escape $1.tex &&
open $1.pdf
}
Now I just do sweaveCache myFile and I get the result opened in Preview (on OS X).
This topic on tex.StackExchange might be interesting for you, as it suggest loading the SweaveListingUtils package in R for easy solution.

Command line arguments R script using Tinn-R

How can I use command line arguments with a R script using Tinn-R.
I can give arguments with a R script like this:
R.exe --args 2010 test.R
And after that read them in the script with commandArgs.
But how can I provide them when using Tinn-R? I cannot find anything in the Tinn-R help
Take a look at this:
SourceForge - Helppages for Tinn
Give a looked in the picture attached below.
I think it should solve your question.

Resources