From: Gabor Grothendieck <ggrothendieck_at_gmail.com>

Date: Sat, 23 Feb 2008 07:44:22 -0500

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. Received on Sat 23 Feb 2008 - 12:49:35 GMT

Date: Sat, 23 Feb 2008 07:44:22 -0500

Just to clarify, what Duncan was referring to as the alternative was nesting the definition of one function in another, e.g. look at FUNx in by.data.frame -- FUNx is available to by.data.frame but is not visible outside of by.data.frame .

On Sat, Feb 23, 2008 at 6:09 AM, Duncan Murdoch <murdoch_at_stats.uwo.ca> wrote:

*>
*

> On 23/02/2008 5:58 AM, Christophe Genolini wrote:

*> > Duncan Murdoch a écrit :
**> >> On 23/02/2008 5:15 AM, Christophe Genolini wrote:
**> >>> Hi the list
**> >>>
**> >>> Is it possible to 'hide' a function from the user ? I cut a big
**> >>> fonction in sub
**> >>> function and I would like to hide the sub function, just like if I
**> >>> declare them
**> >>> in the big function :
**> >>>
**> >>> --------------
**> >>> a <- function(x){
**> >>> b <- function(y){y^2}
**> >>> d <- function(y){y^3}
**> >>> b(x)+d(x)+2
**> >>> }
**> >>> a(2)
**> >>> # [1] 14
**> >>> b(2)
**> >>> # Error :
**> >>> ----------------
**> >>>
**> >>> I would like the same, but with external declaration (for readability) :
**> >>>
**> >>> ----------------
**> >>> b <- function(y){y^2}
**> >>> d <- function(y){y^3}
**> >>> a <- function(x){
**> >>> b(x)+d(x)+2
**> >>> }
**> >>> a(2)
**> >>> # [1] 14
**> >>> b(2)
**> >>> # Error
**> >>> ----------------
**> >>>
**> >>> Is it possible ?
**> >> Yes, as long as you're using a package with a NAMESPACE, just don't
**> >> export b and d. There are other ways too, but they don't improve
**> >> readability.
**> >>
**> >> Duncan Murdoch
**> > If I understand, it is possible only in a package, not in a programme
**> > (unless the "other ways"), is that it ?
**>
**> Yes, that's right. Here's one of the other ways:
**>
**> a <- local( {
**> b <- function(y){y^2}
**> d <- function(y){y^3}
**> function(x){
**> b(x)+d(x)+2
**> }
**> })
**>
**> I don't find that more readable than if b and d had been defined locally
**> within a.
**>
**> Duncan Murdoch
**>
**>
**> ______________________________________________
**> 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.
**>
*

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. Received on Sat 23 Feb 2008 - 12:49:35 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Sat 23 Feb 2008 - 14:00:16 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*