match.fun Function in R (Example)
In this R tutorial you’ll learn how to extract the syntax of a function using the match.fun command.
Table of contents:
Let’s dive into it…
Example: Extract Source Code of Function Using match.fun() Command
The following R programming code explains how to use the match.fun argument to return the content of a function in R.
In this example, we’ll return the source code of the sd function:
match.fun(sd) # Apply match.fun function # function (x, na.rm = FALSE) # sqrt(var(if (is.vector(x) || is.factor(x)) x else as.double(x), # na.rm = na.rm)) # <bytecode: 0x556b1119d590> # <environment: namespace:stats>
The previous output of the RStudio console shows the code of the sd function.
Video & Further Resources
If you need more explanations on the examples of this tutorial, I recommend having a look at the following video on my YouTube channel. I’m explaining the contents of this article in the video tutorial.
The YouTube video will be added soon.
Furthermore, you may have a look at the other tutorials on this website:
- match.call Function in R
- Access & Manipulate Body of Function
- List of R Functions
- R Programming Language
At this point you should know how to access and extract the syntax of a function using the match.fun function in the R programming language. Let me know in the comments below, if you have additional questions.
Statistics Globe Newsletter