Predictive Hacks

How to get the Source Code of a function in R

We can get the source code of an R function by running the getAnywhere() command. For example, if we want to get the source code of the rle built-in function we can run:

A single object matching ‘rle’ was found
It was found in the following places
with value

function (x) 
    if (!is.vector(x) && !is.list(x)) 
        stop("'x' must be a vector of an atomic type")
    n <- length(x)
    if (n == 0L) 
        return(structure(list(lengths = integer(), values = x), 
            class = "rle"))
    y <- x[-1L] != x[-n]
    i <- c(which(y |, n)
    structure(list(lengths = diff(c(0L, i)), values = x[i]), 
        class = "rle")
<bytecode: 0x00000271304c55a0>
<environment: namespace:base>

For more information, you can have a look at the Stackoverflow discussion. Finally, we have written a post on how to get the source code of a function in Python.

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore


Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.


Intro to Chatbots with HuggingFace

In this tutorial, we will show you how to use the Transformers library from HuggingFace to build chatbot pipelines. Let’s