[R] hide body of function

Bill.Venables@CMIS.CSIRO.AU Bill.Venables at CMIS.CSIRO.AU
Fri Mar 30 06:07:01 CEST 2001



| From: victor m [mailto:mi_victor at yahoo.com]
| Sent: Friday, 30 March 2001 12:53
| To: r-help at hypatia.math.ethz.ch
| Subject: [R] hide body of function
| 
| 
| I would like to hide the body of function, when the
| user types the name of that function. 
| For example, I've created "ff" function (cut/paste 
| from R-plus session):
| > ff<-function() {
| a <- 5
| }
| #then, if the user types "ff"
| > ff
| function()           		# This part is shown but I'd like
| 						#  this body to be
| 						#  hidden from the user, if
possible.
| {                        #
|    a <- 5                #
| }                        #
| >
| 
| #Thanks.
| Victor

First I should point out that your function does nothing.  At the end of the
function the local variable, a, will simply be garbage collected.

Secondly, what to you mean "hidden from the user"?  If you mean you want to
write code that only you can read and anyone else looking at your code will
be unable to see it whether they want to do so or not, then I am glad to say
this is impossible and about as contrary to the philosophy as you can get.
(You don't work for Microsoft, do you?)

Thirdly, if you mean you want the user to be able to look at the function
arguments only without being bothered by the body then the tool you need is
args()

Finally, for academic completeness, it is easy to write a function so that
when it is normally printed it will only show its arguments.  Here's one
way:

ff <- function(x) {
		sqrt(x+1)
	}

class(ff) <- "occult"
print.occult <- function(x, ...)
	print(args(x))
	invisible(x)
}

Now when you simply type

> ff

what you will see will (almost) be just the arguments.

Bill Venables.
--
Bill Venables, CSIRO/CMIS Environmetrics Project
Email: Bill.Venables at cmis.csiro.au
Phone: +61 7 3826 7251
Fax:   +61 7 3826 7304
Postal: PO Box 120, Cleveland, Qld 4163, AUSTRALIA


 
| 
| __________________________________________________
| Do You Yahoo!?
| Get email at your own domain with Yahoo! Mail. 
| http://personal.mail.yahoo.com/?.refer=text
| -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
| -.-.-.-.-.-.-.-.-
| r-help mailing list -- Read 
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list