Methods selection for an inherited S4 class

Multi tool use
My question is how to apply the generic function plot()
using my new method for my inherited S4 class.
I extend the existing S4 class (whose name is stanfit) in rstan, say lowerS4class
, and define a new method for generic function plot
for the extended (inherited) S4 class, say upperS4class
.
But the following undesired selection (i.e. the selected method is the method
for the lower S4 class) occur with the following Note
in the R console when I apply the generic function plot()
for the extended S4 class.
Note: method with signature "lowerS4class#missing" chosen for function ‘plot’,
target signature "upperS4clss#missing".
"upperS4clss#ANY" would also be valid
By the following, The generic function plot()
choose for new method for upper class:
plot( x ,signature("upperS4class"))
But I do not want to assume that users for my package know the name of S4 class. By the following, the new method is also chosen: (Why ?)
plot( x ,signature("lowerS4class"))
But the following the method from another package for lower class is used.
plot( x )
Edit for comment-----------------------------------------
Inheritance
setMethod("plot",
signature(x = "upperS4class"),
definition = function(x){
foo(x)
}
)
where foo
is a function defined by me.
Def. for upperS4class
upperS4class <- setClass(
#Name for upper class
"upperS4class",
# Inheritance
contains = "lowerS4class"
# New slots
representation(
.....
),
# Initial values for new slots
prototype(
.....
),
)
r inheritance methods s4 generic-function
add a comment |
My question is how to apply the generic function plot()
using my new method for my inherited S4 class.
I extend the existing S4 class (whose name is stanfit) in rstan, say lowerS4class
, and define a new method for generic function plot
for the extended (inherited) S4 class, say upperS4class
.
But the following undesired selection (i.e. the selected method is the method
for the lower S4 class) occur with the following Note
in the R console when I apply the generic function plot()
for the extended S4 class.
Note: method with signature "lowerS4class#missing" chosen for function ‘plot’,
target signature "upperS4clss#missing".
"upperS4clss#ANY" would also be valid
By the following, The generic function plot()
choose for new method for upper class:
plot( x ,signature("upperS4class"))
But I do not want to assume that users for my package know the name of S4 class. By the following, the new method is also chosen: (Why ?)
plot( x ,signature("lowerS4class"))
But the following the method from another package for lower class is used.
plot( x )
Edit for comment-----------------------------------------
Inheritance
setMethod("plot",
signature(x = "upperS4class"),
definition = function(x){
foo(x)
}
)
where foo
is a function defined by me.
Def. for upperS4class
upperS4class <- setClass(
#Name for upper class
"upperS4class",
# Inheritance
contains = "lowerS4class"
# New slots
representation(
.....
),
# Initial values for new slots
prototype(
.....
),
)
r inheritance methods s4 generic-function
Could you post your method definition (or a skeleton of it)? Is the method defined for signaturex=upperS4class,y=missing
or justx=upperS4class
? (I am also assuming your class definition starts withsetClass("upperS4class",contains="lowerS4class",...) -> upperS4class
)
– JDL
2 days ago
Thank you for reply. I am not sure your codey=missing
. Is it needed ?
– Camford Oxbridge
3 hours ago
add a comment |
My question is how to apply the generic function plot()
using my new method for my inherited S4 class.
I extend the existing S4 class (whose name is stanfit) in rstan, say lowerS4class
, and define a new method for generic function plot
for the extended (inherited) S4 class, say upperS4class
.
But the following undesired selection (i.e. the selected method is the method
for the lower S4 class) occur with the following Note
in the R console when I apply the generic function plot()
for the extended S4 class.
Note: method with signature "lowerS4class#missing" chosen for function ‘plot’,
target signature "upperS4clss#missing".
"upperS4clss#ANY" would also be valid
By the following, The generic function plot()
choose for new method for upper class:
plot( x ,signature("upperS4class"))
But I do not want to assume that users for my package know the name of S4 class. By the following, the new method is also chosen: (Why ?)
plot( x ,signature("lowerS4class"))
But the following the method from another package for lower class is used.
plot( x )
Edit for comment-----------------------------------------
Inheritance
setMethod("plot",
signature(x = "upperS4class"),
definition = function(x){
foo(x)
}
)
where foo
is a function defined by me.
Def. for upperS4class
upperS4class <- setClass(
#Name for upper class
"upperS4class",
# Inheritance
contains = "lowerS4class"
# New slots
representation(
.....
),
# Initial values for new slots
prototype(
.....
),
)
r inheritance methods s4 generic-function
My question is how to apply the generic function plot()
using my new method for my inherited S4 class.
I extend the existing S4 class (whose name is stanfit) in rstan, say lowerS4class
, and define a new method for generic function plot
for the extended (inherited) S4 class, say upperS4class
.
But the following undesired selection (i.e. the selected method is the method
for the lower S4 class) occur with the following Note
in the R console when I apply the generic function plot()
for the extended S4 class.
Note: method with signature "lowerS4class#missing" chosen for function ‘plot’,
target signature "upperS4clss#missing".
"upperS4clss#ANY" would also be valid
By the following, The generic function plot()
choose for new method for upper class:
plot( x ,signature("upperS4class"))
But I do not want to assume that users for my package know the name of S4 class. By the following, the new method is also chosen: (Why ?)
plot( x ,signature("lowerS4class"))
But the following the method from another package for lower class is used.
plot( x )
Edit for comment-----------------------------------------
Inheritance
setMethod("plot",
signature(x = "upperS4class"),
definition = function(x){
foo(x)
}
)
where foo
is a function defined by me.
Def. for upperS4class
upperS4class <- setClass(
#Name for upper class
"upperS4class",
# Inheritance
contains = "lowerS4class"
# New slots
representation(
.....
),
# Initial values for new slots
prototype(
.....
),
)
r inheritance methods s4 generic-function
r inheritance methods s4 generic-function
edited 48 mins ago
asked Dec 28 '18 at 3:05


Camford Oxbridge
528
528
Could you post your method definition (or a skeleton of it)? Is the method defined for signaturex=upperS4class,y=missing
or justx=upperS4class
? (I am also assuming your class definition starts withsetClass("upperS4class",contains="lowerS4class",...) -> upperS4class
)
– JDL
2 days ago
Thank you for reply. I am not sure your codey=missing
. Is it needed ?
– Camford Oxbridge
3 hours ago
add a comment |
Could you post your method definition (or a skeleton of it)? Is the method defined for signaturex=upperS4class,y=missing
or justx=upperS4class
? (I am also assuming your class definition starts withsetClass("upperS4class",contains="lowerS4class",...) -> upperS4class
)
– JDL
2 days ago
Thank you for reply. I am not sure your codey=missing
. Is it needed ?
– Camford Oxbridge
3 hours ago
Could you post your method definition (or a skeleton of it)? Is the method defined for signature
x=upperS4class,y=missing
or just x=upperS4class
? (I am also assuming your class definition starts with setClass("upperS4class",contains="lowerS4class",...) -> upperS4class
)– JDL
2 days ago
Could you post your method definition (or a skeleton of it)? Is the method defined for signature
x=upperS4class,y=missing
or just x=upperS4class
? (I am also assuming your class definition starts with setClass("upperS4class",contains="lowerS4class",...) -> upperS4class
)– JDL
2 days ago
Thank you for reply. I am not sure your code
y=missing
. Is it needed ?– Camford Oxbridge
3 hours ago
Thank you for reply. I am not sure your code
y=missing
. Is it needed ?– Camford Oxbridge
3 hours ago
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53953228%2fmethods-selection-for-an-inherited-s4-class%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53953228%2fmethods-selection-for-an-inherited-s4-class%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
h,6UwAA30tgDlWAK hx,8CQuQqz,ymgnujEWgZnPinj1gKMP suHT49N61Br,edfEN bIoS s7qEcP2wUTFvyx hyt,a8O9b1CFo81I
Could you post your method definition (or a skeleton of it)? Is the method defined for signature
x=upperS4class,y=missing
or justx=upperS4class
? (I am also assuming your class definition starts withsetClass("upperS4class",contains="lowerS4class",...) -> upperS4class
)– JDL
2 days ago
Thank you for reply. I am not sure your code
y=missing
. Is it needed ?– Camford Oxbridge
3 hours ago