Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ftype] Question regarding the s3 method type #47

Open
dhuebner opened this issue Jun 8, 2016 · 2 comments
Open

[ftype] Question regarding the s3 method type #47

dhuebner opened this issue Jun 8, 2016 · 2 comments

Comments

@dhuebner
Copy link

dhuebner commented Jun 8, 2016

I have a question regarding the usage of pryr functions in own code.
Following is a function I've created:
f <- function(var) {pryr::ftype(var)}

Calling "ftype" directly for 't.data.frame' results in an expected output:

pryr::ftype(t.data.frame)
[1] "s3" "method"`

Calling the same 't.data.frame' from my function prints a wrong result:

f(t.data.frame)
[1] "function"

Is there some trick for "S3 method" recognition ?

@marami52
Copy link

marami52 commented Jun 8, 2016

@dhuebner you always ask hard and good questions! :) I couldn't figure it out. I sent an email to Hadely (author of pryr) and will keep you posted.

@alexey0308
Copy link

Hi Dennis @dhuebner,

ftype uses parent.frame() in order to derive the type (in this case, the environment of
the function f call).

You may use this workaround in order to go one level back
(or, for example, to the global environment, if env=.GlobalEnv):

> f <- function(var, env=parent.frame()) {
+     eval(substitute(pryr::ftype(var)), envir = env)
+ }
> 
> f(t.data.frame)
[1] "s3"     "method"

Hope this helps.

Regards,
Alex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants