Re: [R-pkg-devel] Concise Summary For Any Variety Of R Function

2021-10-20 Thread Simon Urbanek


Dario,

there is not such thing as S4 function. However, all functions have an 
environment and for functions from packages that environment will be the 
namespace of the package. So in those special cases you can use 
environmentName() to get the name, e.g.:

> who = function(f) cat(deparse(substitute(f)), "from", 
> environmentName(environment(f)),"\n")
> who(ls)
ls from base 
> who(rnorm)
rnorm from stats 
> who(who)
who from R_GlobalEnv 

However, this won't work for functions defined in arbitrary environments which 
have no name:

> local({ f= function(x) x
+ who(f)
+ })
f from  

Depending on how much time you want to spend, you can do a search up the frames 
to find a named environment, but the concept you're trying to implement looks 
very fragile.

Cheers,
Simon



> On Oct 19, 2021, at 9:00 PM, Dario Strbenac  
> wrote:
> 
> Good day,
> 
> I would like to create a concise show method for an S4 class that I am 
> developing. One class slot stores a function specified by the end user. It 
> could be a basic function, an S3 function, an S4 function. For S4 functions, 
> I can get a concise representation:
> 
>> capture.output(showMethods(limmaSelection))[1]
> [1] "Function: limmaSelection (package ClassifyR)"
> 
> If the user specified the function bdiag from Matrix, how could I generalise 
> the show code to describe the function, such that the output would be 
> "Function bdiag from package Matrix" and simiarly for an S3 function?
> 
> --
> Dario Strbenac
> University of Sydney
> Camperdown NSW 2050
> Australia
> __
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
> 

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


[R-pkg-devel] Concise Summary For Any Variety Of R Function

2021-10-19 Thread Dario Strbenac
Good day,

I would like to create a concise show method for an S4 class that I am 
developing. One class slot stores a function specified by the end user. It 
could be a basic function, an S3 function, an S4 function. For S4 functions, I 
can get a concise representation:

> capture.output(showMethods(limmaSelection))[1]
[1] "Function: limmaSelection (package ClassifyR)"

If the user specified the function bdiag from Matrix, how could I generalise 
the show code to describe the function, such that the output would be "Function 
bdiag from package Matrix" and simiarly for an S3 function?

--
Dario Strbenac
University of Sydney
Camperdown NSW 2050
Australia
__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel