[R] How to get the definition of a function if it is masked by a variable?
John Fox
jfox at mcmaster.ca
Sat May 29 00:49:43 CEST 2010
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 guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list