2

According to the documentation, source() takes a default option echo = verbose, which can get old fast when testing functions. How can I set this to be FALSE just for source() in a simple way (such as an .Rprofile setting)?

I tried setting options(echo=FALSE) but that throws a wrench in the terminal functioning:

> options(echo=FALSE)

5
[1] 5
options(echo=TRUE)
> 
Scarabee
  • 5,437
  • 5
  • 29
  • 55
bright-star
  • 6,016
  • 6
  • 42
  • 81

4 Answers4

4

If you are using RStudio, the Source button can perform either "Source" or "Source with Echo" using the little dropdown arrow to select between then. The button will then continue to run with the last chosen option.

yeliabsalohcin
  • 720
  • 1
  • 6
  • 14
2

Redefine source:

source = function (file, local = FALSE, print.eval = echo,
                   verbose = getOption("verbose"),
                   prompt.echo = getOption("prompt"), max.deparse.length = 150,
                   chdir = FALSE, encoding = getOption("encoding"),
                   continue.echo = getOption("continue"), skip.echo = 0,
                   keep.source = getOption("keep.source")) {
    base::source(file, local, echo = FALSE, print.eval, verbose, prompt.echo,
                 max.deparse.length, chdir, encoding, continue.echo, skip.echo,
                 keep.source)
}

Terrible, I know. But effective.

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
2

How about

library(Defaults)
setDefaults("source",echo=FALSE)

?

This is similar to (but not quite identical/somewhat simpler than) the answer to this question.

Since the Defaults package was archived 6 months after this question was answered, you either would have to get it from here or use devtools::install_version("Defaults","1.1-1"), or fall back to @KonradRudolph's answer.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • 1
    For posterity, also note that RStudio assumes that whatever source option you clicked in the sub-menu (with or without echo) is what you would like every time you click the Source button...and thus no option or explanation about this feature, which is what led me to ask this question in the first place. – bright-star Jun 11 '14 at 22:05
  • No, [Package ‘Defaults’ was removed from the CRAN repository way back on 2014-10-03](https://cran.r-project.org/web/packages/Defaults/index.html) – smci Jun 27 '18 at 01:44
  • OK, but I answered this question 6 months before that! – Ben Bolker Jun 27 '18 at 02:23
0

No, source does not take a "default option". It takes a logical argument echo, which defaults to the value of verbose. If the caller doesn't pass verbose either, that argument, in turn, defaults to getOption("verbose"). So if you wanted to set a global option to affect echoing of the input text, you would do options(verbose=FALSE). BTW, that's the setting of this option by default anyway, so you only need to change any of the above if you set it differently.

Quigi
  • 149
  • 1
  • 8