[R] SPlus script

Duncan Murdoch murdoch.duncan at gmail.com
Fri Jun 7 13:05:59 CEST 2013


On 13-06-06 6:22 PM, Rolf Turner wrote:
> On 07/06/13 03:19, Scott Raynaud wrote:
>> I actually had tried placing arguments in the call but it didn't work.   However, I did
>> not think about writing it to a variable and printing.  That seems to have done the
>> trick.  Funny, I don't remember having to do that before, but that's not surprising.
>>
>
> If I remember correctly --- haven't used Splus for decades --- this is a
> difference
> between Splus and R.
>
> In R the output of a function is returned *invisibly* if that function
> is called
> from within another function.  And source() is one such other function.

Actually this depends on the caller.  source() does return its results 
invisibly, but many other functions don't.

source() is unusual in another way that came up recently (on R-devel, I 
think):  it calls withVisible() on the code that it evaluates, which 
means that instead of a simple value it will return a list containing 
the value and an indicator about whether it should be displayed. It 
returns this list invisibly, leaving it up to whoever called source() to 
decide whether to display the value or not.

Duncan Murdoch

>
> So if you have a script, say "melvin" with the single line:
>
>       sin(42)
>
> and in R you execute
>
>       source("melvin")
>
> you will see no output.  If in another script, say "clyde" you have the
> single line
>
>       print(sin(42))
>
> and in R you execute
>
>       source("clyde")
>
> you will see
>
>       [1] -0.9165215
>
> In Splus, IIRC, the print() call is unnecessary.  I.e. you would get the
> same
> result by sourcing "melvin" and "clyde".
>
> Current Splus users may correct me if I am wrong about this.
>
>       cheers,
>
>           Rolf Turner
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list