I accidentally found this old thread on "hiding the function's code" to
(presumably) avoid confusing the users. And here is my amateurish question:
why can't it be done just by defining a print.function, something like this:

print.function<-function(x) cat("function", deparse(substitute(x)), "is top
secret\n")

It can be done in a sense, but what happens is:

> mean
function (x, ...)
UseMethod("mean")
<environment: namespace:base>
> print(mean)
function mean is top secret

- I'm not interested in hiding the code from anyone, but it would just be
interesting to know what is happening here.. i.e., why is my print.function
only used if print is called explicitly. (Using R 2.7.0 on Windows.)

Kenn

Kenn Konstabel
Department of Chronic Diseases
National Institute for Health Development
Hiiu 42
Tallinn, Estonia


On Thu, Jul 17, 2008 at 6:55 PM, Peter Dalgaard <p.dalgaard@biostat.ku.dk>wrote:

> Tudor Bodea wrote:
>
>> Dear UseRs:
>>
>> I intend to write a package to handle the basic operations a revenue
>> management
>> analyst has to deal with on a regular basis (e.g., demand untruncation,
>> capacity allocation, pricing decisions, etc.).  Following the directions
>> posted
>> by Peter Rossi (Making R Packages under Windows: A Tutorial, January 2006)
>> I
>> was able to build an interim package that currently consists of one simple
>> function (e.g., fun).  After the package is loaded and the function is
>> invoked
>> without any parameters (e.g., > fun) the body of the function is displayed
>> on
>> the screen underneath the function call.  Since the user does not need to
>> know
>> the internal structure of the function, I am wondering if there is a way
>> to
>> hide this information. I have looked into some of the material that Paul
>> Murrell and John Chambers among others posted but I have not really
>> understood
>> how to incorporate this information into the package building process.  If
>> you
>> already experienced this issue and have some useful suggestions, I would
>> really
>> appreciate your taking the time to share them with me.  For this project,
>> I am
>> using R2.7.1 on a Windows XP machine.
>>
>>
> A simple way is
>
> > print.invisible <- function(x) cat("Printing disabled\n")
> > class(ls) <- "invisible"
> > ls
> Printing disabled
>
> Of course, unclass(ls) still shows the definition, but I assume that the
> purpose was never to hide the progamming, just to avoid confusing users.
> Also of course, the same thing applies to all other functions in the
> system....
>
> And, btw, "fun" is not "invoking the function without parameters", that
> would be "fun()". Typing the name is a request to see the function object.
>
> --
>  O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
>  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
> (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)              FAX: (+45) 35327907
>
> ______________________________________________
> R-help@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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]

