thmsfuller066 at gmail.com
2010-May-28 18:54 UTC
[R] How to get the definition of a function if it is masked by a variable?
Hello, Normally, if I type a function name, it shows the function definition. When the function is masked by a variable with the same name, it doesn't show the function definition any more. Can anyone please tell me a way how to retrieve the function definition even if it is masked by a variable?> x=1:3 > length(x)[1] 3> lengthfunction (x) .Primitive("length")> length=10 > length[1] 10> length(x)[1] 3 -- Tom
John Fox
2010-May-28 22:49 UTC
[R] How to get the definition of a function if it is masked by a variable?
Dear Tom, You can use getAnywhere(); for example:> mean <- 1> getAnywhere("mean")2 differing objects matching 'mean' were found in the following places .GlobalEnv package:base namespace:base Use [] to view one of them> getAnywhere("mean")[1][1] 1> getAnywhere("mean")[2]function (x, ...) UseMethod("mean") <environment: namespace:base>> getAnywhere("mean")[3]function (x, ...) UseMethod("mean") <environment: namespace:base> I hope this helps, John -------------------------------- John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]On> Behalf Of thmsfuller066 at gmail.com > Sent: May-28-10 2:55 PM > To: r-help at r-project.org > Subject: [R] How to get the definition of a function if it is masked by a > variable? > > Hello, > > Normally, if I type a function name, it shows the function definition. > When the function is masked by a variable with the same name, it > doesn't show the function definition any more. Can anyone please tell > me a way how to retrieve the function definition even if it is masked > by a variable? > > > x=1:3 > > length(x) > [1] 3 > > length > function (x) .Primitive("length") > > length=10 > > length > [1] 10 > > length(x) > [1] 3 > > -- > Tom > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Greg Snow
2010-May-29 01:15 UTC
[R] How to get the definition of a function if it is masked by a variable?
?'::' -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of thmsfuller066 at gmail.com > Sent: Friday, May 28, 2010 12:55 PM > To: r-help at r-project.org > Subject: [R] How to get the definition of a function if it is masked by > a variable? > > Hello, > > Normally, if I type a function name, it shows the function definition. > When the function is masked by a variable with the same name, it > doesn't show the function definition any more. Can anyone please tell > me a way how to retrieve the function definition even if it is masked > by a variable? > > > x=1:3 > > length(x) > [1] 3 > > length > function (x) .Primitive("length") > > length=10 > > length > [1] 10 > > length(x) > [1] 3 > > -- > Tom > > ______________________________________________ > 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.