Dear R-Users,
I want to change the args() function to return by default the arguments
of the default generic function:
args = function(name, default = TRUE) {
?? ?# TODO: && is.function.generic();
?? ?if(default) {
?? ???? fn = match.call()[[2]];
?? ???? fn = paste0(as.character(fn), ".default");
?? ???? name = fn;
?? ?}
?? ?.Internal(args(name));
}
Is there a nice way to find out if a function is generic: something like
is.function.generic()?
Many thanks,
Leonard
=======
Note:
- the latest version of this code will be on GitHub:
https://github.com/discoleo/R/commits/master/Stat/Tools.Code.R
Default Generic function for: args(name, default = TRUE)
3 messages · Bert Gunter, Leonard Mada
?.S3methods f <- function()(2)
length(.S3methods(f))
[1] 0
length(.S3methods(print))
[1] 206 There may be better ways, but this is what came to my mind. -- Bert On Wed, Mar 8, 2023 at 11:09?AM Leonard Mada via R-help <
r-help at r-project.org> wrote:
Dear R-Users,
I want to change the args() function to return by default the arguments
of the default generic function:
args = function(name, default = TRUE) {
# TODO: && is.function.generic();
if(default) {
fn = match.call()[[2]];
fn = paste0(as.character(fn), ".default");
name = fn;
}
.Internal(args(name));
}
Is there a nice way to find out if a function is generic: something like
is.function.generic()?
Many thanks,
Leonard
=======
Note:
- the latest version of this code will be on GitHub:
https://github.com/discoleo/R/commits/master/Stat/Tools.Code.R
______________________________________________ R-help at 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.
Dear Bert,
Thank you for the idea.
It works, although a little bit ugly. The original code generated an
ugly warning as well. I have modified it slightly:
is.function.generic = function(name) {
?? ?# TODO: is.function.generic();
?? ?# - this version is a little bit ugly;
?? ?# - S4: if(isGeneric(name));
?? ?length(do.call(.S3methods, list(name))) > 0;
}
The latest code is on GitHub:
https://github.com/discoleo/R/blob/master/Stat/Tools.Code.R
Sincerely,
Leonard
### initial variant:
is.function.generic = function(name) {
?? ?length(.S3methods(name)) > 0;
}
is.function.generic(plot)
# [1] TRUE
# Warning message:
# In .S3methods(name) :
#? generic function 'name' dispatches methods for generic 'plot'
On 3/8/2023 9:24 PM, Bert Gunter wrote:
?.S3methods f <- function()(2)
length(.S3methods(f))
[1] 0
length(.S3methods(print))
[1] 206
There may be better ways, but this is what came to my mind.
-- Bert
On Wed, Mar 8, 2023 at 11:09?AM Leonard Mada via R-help
<r-help at r-project.org> wrote:
Dear R-Users,
I want to change the args() function to return by default the
arguments
of the default generic function:
args = function(name, default = TRUE) {
??? ?# TODO: && is.function.generic();
??? ?if(default) {
??? ???? fn = match.call()[[2]];
??? ???? fn = paste0(as.character(fn), ".default");
??? ???? name = fn;
??? ?}
??? ?.Internal(args(name));
}
Is there a nice way to find out if a function is generic:
something like
is.function.generic()?
Many thanks,
Leonard
=======
Note:
- the latest version of this code will be on GitHub: [edited]
https://github.com/discoleo/R/blob/master/Stat/Tools.Code.R
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://eu01.z.antigena.com/l/WZHjscrVT77vHCg4mpOMD6G3~71hGfsI0mptEj63qDZ99ANSHBBoL682m4B1eeO4WJY2kWbEgf4nD6ORsu0Q1G3~fQBVXndWyFwTK0o1QPwCDSM4XcAT_kGxZsqFs0nU5LG9FCvwtZX7Lsta070KiGRfGTdgKbpCnJ9vNNn
PLEASE do read the posting guide
https://eu01.z.antigena.com/l/Efe9Tc5mAjjlHqsLNsVk2LXfGus-29wP9xeO3U-ofLI66Tb7tlGzxrP41MCDN4tLHzRIy8CNw2lGBcBL8IJrlNylyzjgGj38QiP1AqozMauoon-m6yOtCa2oLqMafoHs6kmA~KUXemho3gXsgpaNdEzAmkcv5WqXCZJU9h
and provide commented, minimal, self-contained, reproducible code.