Missing information in source()

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Missing information in source()

Tom Backer Johnsen-2
Dear R-help,

I am running a Mac under Sierra, with R version 3.4.2 and RStudio 1.1.383.  When running head () or tail () on an object in a script using source (<script name>) nothing appears in the output file, but if I use these commands in the normal R window the normal output appears.

What am I doing wrong?

Tom Backer Johnsen
University of Bergen
Norway
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Missing information in source()

Rui Barradas
Hello,

Try

print(head(...))

Hope this helps,

Rui Barradas

Em 07-11-2017 20:01, Tom Backer Johnsen escreveu:

> Dear R-help,
>
> I am running a Mac under Sierra, with R version 3.4.2 and RStudio 1.1.383.  When running head () or tail () on an object in a script using source (<script name>) nothing appears in the output file, but if I use these commands in the normal R window the normal output appears.
>
> What am I doing wrong?
>
> Tom Backer Johnsen
> University of Bergen
> Norway
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Missing information in source()

R help mailing list-2
In reply to this post by Tom Backer Johnsen-2
Either change your script by adding print(...) calls where you want to see
something printed or change the call to source() by adding print.eval=TRUE
or echo=TRUE.   E.g.,

> cat(file = tf <- tempfile(), "head(10:1)\ntail(letters)\nx <-
gamma(0:4)\nx\n")
> source(tf)
Warning message:
In gamma(0:4) : NaNs produced
> source(tf, print.eval=TRUE)
[1] 10  9  8  7  6  5
[1] "u" "v" "w" "x" "y" "z"
[1] NaN   1   1   2   6
Warning message:
In gamma(0:4) : NaNs produced
> source(tf, echo=TRUE, print.eval=TRUE)

> head(10:1)
[1] 10  9  8  7  6  5

> tail(letters)
[1] "u" "v" "w" "x" "y" "z"

> x <- gamma(0:4)

> x
[1] NaN   1   1   2   6
Warning message:
In gamma(0:4) : NaNs produced
>

Calling options(warn=1) before calling source() will keep the warnings near
the lines that caused them.


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Tue, Nov 7, 2017 at 12:01 PM, Tom Backer Johnsen <[hidden email]> wrote:

> Dear R-help,
>
> I am running a Mac under Sierra, with R version 3.4.2 and RStudio
> 1.1.383.  When running head () or tail () on an object in a script using
> source (<script name>) nothing appears in the output file, but if I use
> these commands in the normal R window the normal output appears.
>
> What am I doing wrong?
>
> Tom Backer Johnsen
> University of Bergen
> Norway
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Missing information in source()

Duncan Murdoch-2
In reply to this post by Tom Backer Johnsen-2
On 07/11/2017 3:01 PM, Tom Backer Johnsen wrote:
> Dear R-help,
>
> I am running a Mac under Sierra, with R version 3.4.2 and RStudio 1.1.383.  When running head () or tail () on an object in a script using source (<script name>) nothing appears in the output file, but if I use these commands in the normal R window the normal output appears.
>
> What am I doing wrong?

You aren't printing the results.  source() has an argument "print.eval"
which defaults to FALSE; you can change it.  A common way to do that is
to set echo=TRUE, but echoing the input is not necessary.

So use

source(filename, echo = TRUE)

for a lot of output, or

source(filename, print.eval = TRUE)

for somewhat less.

In most cases an explicit print() will be needed if the head() or tail()
is in a loop or in a function.

Duncan Murdoch

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Missing information in source()

Daniel Nordlund-3
In reply to this post by Tom Backer Johnsen-2
On 11/7/2017 12:01 PM, Tom Backer Johnsen wrote:

> Dear R-help,
>
> I am running a Mac under Sierra, with R version 3.4.2 and RStudio 1.1.383.  When running head () or tail () on an object in a script using source (<script name>) nothing appears in the output file, but if I use these commands in the normal R window the normal output appears.
>
> What am I doing wrong?
>
> Tom Backer Johnsen
> University of Bergen
> Norway
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

I believe you need to wrap your call to head/tail in a print statement:

print(head(_whatever_))


Hope this is helpful,


Dan



--
Daniel Nordlund
Port Townsend, WA  USA

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Missing information in source()

Tom Backer Johnsen-2
In reply to this post by Rui Barradas
Hello

Thank you all for most useful responses.  I was looking for answers in the wrong place, that is why I have not responded before!

Tom Backer Johnsen

> On 7 Nov 2017, at 21:25, Rui Barradas <[hidden email]> wrote:
>
> Hello,
>
> Try
>
> print(head(...))
>
> Hope this helps,
>
> Rui Barradas
>
> Em 07-11-2017 20:01, Tom Backer Johnsen escreveu:
>> Dear R-help,
>>
>> I am running a Mac under Sierra, with R version 3.4.2 and RStudio 1.1.383.  When running head () or tail () on an object in a script using source (<script name>) nothing appears in the output file, but if I use these commands in the normal R window the normal output appears.
>>
>> What am I doing wrong?
>>
>> Tom Backer Johnsen
>> University of Bergen
>> Norway
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.