Skip to content

Instantly share code, notes, and snippets.

@jennybc
Last active January 6, 2020 08:09
Show Gist options
  • Save jennybc/4a1bf4e9e1bb3a0a9b56 to your computer and use it in GitHub Desktop.
Save jennybc/4a1bf4e9e1bb3a0a9b56 to your computer and use it in GitHub Desktop.
Search for "natural" usage of a function across all CRAN packages

What if a function in a package has no examples? Or is poorly exampled? Wouldn't it be nice to find functioning instances of it "in the wild"?

Via Twitter, Noam Ross taught me a clever way to do such searches on GitHub. Put this into the GitHub search box to see people using the llply() function from plyr:

"llply" user:cran language:R

Or just click here.

This takes advantage of Gábor Csárdi's unofficial read-only mirror of all CRAN R packages: https://github.com/cran, which also has a pretty webpage: http://cran.github.io.

While I'm at it, I'll also link to Winston Chang's read-only mirror of the R source: https://github.com/wch/r-source.

Remember, read the source!

@hrbrmstr
Copy link

hrbrmstr commented Mar 4, 2015

Add this to your .Rprofile and you can save a wee bit of typing, too:

cranex <- function(what) {
  url <- paste("https://github.com/search?l=r&q=%22", as.character(substitute(what)), "%22+user%3Acran+language%3AR&ref=searchresults&type=Code&utf8=%E2%9C%93", sep="", collapse="")
  browseURL(url)
}

so, now you can just do cranex(llply) or cranex("llply") from the R console :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment