[R] Printing upon calling a function

Avi Gross @v|gro@@ @end|ng |rom ver|zon@net
Mon Nov 30 18:06:29 CET 2020


You need to mention what you actually did to get proper advice. Your problem is at the source.

Simply put, the R interpreter does have somewhat different behavior when the program is directly typed in (or slightly indirectly as in R STUDIO) than when you ask it to open another file as a source, perhaps recursively.

If you read the manual page, "source()" has lots of options.


The default is to change some of the behavior with the assumption there is no user typing things in and waiting for responses. One of the options will change the behavior to make statements auto-print.  Look to see if

source(..., echo=TRUE)

gets what you want. Obviously the "..." above is replaced with your additional code. Of course, an explicit print statement works too. You may also want to look at the print.eval option.

What next? Will you now tell us you forgot that you used the sink(file="hide.txt") function in the code and wonder why it does not print to your terminal? 

-----Original Message-----
From: R-help <r-help-bounces using r-project.org> On Behalf Of Steven Yen
Sent: Monday, November 30, 2020 5:55 AM
To: Stefan Evert <stefanML using collocations.de>
Cc: R-help Mailing List <r-help using r-project.org>
Subject: Re: [R] Printing upon calling a function

No. I wrote the function so I am sure no "invisible" command was used. 
Strangely enough, compiling the function isto part of a package, results were NOT printed. Yes if I call the function during run, by preceding the call with a line that attach the source code:


it did print. I do not understand.

On 2020/11/30 下午 06:41, Stefan Evert wrote:
>> On 30 Nov 2020, at 10:41, Steven Yen <styen using ntu.edu.tw> wrote:
>> Thanks. I know, my point was on why I get something printed by simply doing line 1 below and at other occasions had to do line 2.
>> me.probit(obj)
> That means the return value of me.probit() has been marked as 
> invisible, so it won't auto-print.  You have to use an explicit print
> 	print(me.probit(obj))
> or use your work-around to convince R that you actually meant to print the output.
> If you dig through the full code of me.probit(), you'll probably find the function invisible() called somewhere.
> Best,
> Stefan

R-help using r-project.org 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.

Scanned by McAfee and confirmed virus-free.	
Find out more here: https://bit.ly/2zCJMrO

More information about the R-help mailing list